Unix Shell - compare two text files

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2007 > compare two text files





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author compare two text files
Unix_shell

2007-02-22, 7:19 am

Hi,

I want to compare two text files(contains numbers) and I need a shell
script for this to get what are the simmilar fiels and the differents
fiels in these two text files (the result can be in another files).
an example of these two files:
file1:
34556678
33236789
32223456
31458909
30113256
file2:
33557890
31458909
33236789
30113256
33556788

Thanks a lot for your help.

Janis

2007-02-22, 7:19 am

On 22 Feb., 11:04, "Unix_shell" <marouane.s...@gmail.com> wrote:
> Hi,
>
> I want to compare two text files(contains numbers) and I need a shell
> script for this to get what are the simmilar fiels and the differents
> fiels in these two text files (the result can be in another files).


Several possibilities; for unsorted files one way is...

comm <(sort file1) <(sort file2)


Janis

> an example of these two files:
> file1:
> 34556678
> 33236789
> 32223456
> 31458909
> 30113256
> file2:
> 33557890
> 31458909
> 33236789
> 30113256
> 33556788
>
> Thanks a lot for your help.



Bruce Barnett

2007-02-22, 7:19 am

"Unix_shell" <marouane.saad@gmail.com> writes:

> Hi,
>
> I want to compare two text files(contains numbers) and I need a shell
> script for this to get what are the simmilar fiels and the differents
> fiels in these two text files (the result can be in another files).
> an example of these two files:


read the manual pages on
sort
diff
comm


--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Unix_shell

2007-02-22, 7:19 am

Hi,
I used this command : comm <(sort file1) <(sort file2)
but the problem that I have a big number to compare (more than100K) it
will be useful that I can have the result in three differents files.
(common, present in file1, present in file2)

Thanks a lot.

On 22 f=E9v, 13:34, "Janis" <janis_papanag...@hotmail.com> wrote:
> On 22 Feb., 11:04, "Unix_shell" <marouane.s...@gmail.com> wrote:
>
>
>
> Several possibilities; for unsorted files one way is...
>
> comm <(sort file1) <(sort file2)
>
> Janis
>
>
>
>
ts -[vbcol=seagreen]
>
> - Afficher le texte des messages pr=E9c=E9dents -



Michael Tosch

2007-02-22, 1:18 pm

Janis wrote:
> On 22 Feb., 11:04, "Unix_shell" <marouane.s...@gmail.com> wrote:
>
> Several possibilities; for unsorted files one way is...
>
> comm <(sort file1) <(sort file2)
>
>


Huh?
Is this supported by all shells?


--
Michael Tosch @ hp : com
Janis

2007-02-22, 1:18 pm

On 22 Feb., 13:58, "Unix_shell" <marouane.s...@gmail.com> wrote:

[Please don't top-post.]

> Hi,
> I used this command : comm <(sort file1) <(sort file2)
> but the problem that I have a big number to compare (more than100K) it
> will be useful that I can have the result in three differents files.
> (common, present in file1, present in file2)


Yes. The simplest may be to use options to the comm command (man comm)
and call it three times with the appropriate options.

Janis
[vbcol=seagreen]
>
> Thanks a lot.
>
> On 22 f=E9v, 13:34, "Janis" <janis_papanag...@hotmail.com> wrote:
>
>
>
>
>
>
>
>
ents -[vbcol=seagreen]
>


Janis

2007-02-22, 1:18 pm

On 22 Feb., 15:19, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote:
> Janis wrote:
>
>
>
>
> Huh?
> Is this supported by all shells?


I am very sure that process substitution is *not* supported by "_all_
shells".
(It is supported by all the shells that I use, though.)

Janis

>
> --
> Michael Tosch @ hp : com



jegan

2007-02-23, 1:21 am

Hi ,

The best and simplest way is to use

>sort file1 > file3
>sort file2 > file4
> diff file3 file4 | grep ">" | cut -f2 -d' ' >file5 ( this will have files which are present in second file alone.)


Regards,
JeganR

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com