Home » Infrastructure » Unix » Unix file comparison
Unix file comparison [message #179863] Thu, 29 June 2006 02:13 Go to next message
Brayan
Messages: 315
Registered: June 2002
Senior Member
Hi,

I need some help in unix scripting.

I've 2 files.

"File1" contents like:
1
2
3
4
5

"File2" contents like:
1
4
2
5

I need a output in "File3" as :

3

Here 3 is missing in "File2"


Thanking you in advance,
Ronald.
Re: Unix file comparison [message #179869 is a reply to message #179863] Thu, 29 June 2006 02:37 Go to previous messageGo to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member



 diff file1 file2 > file3
 


For more details ....

Re: Unix file comparison [message #179871 is a reply to message #179869] Thu, 29 June 2006 02:46 Go to previous messageGo to next message
Brayan
Messages: 315
Registered: June 2002
Senior Member
Hi,

In this case I get output like3d2
3d2
< 3


Instead I want just
3

Thankx.
Re: Unix file comparison [message #180037 is a reply to message #179871] Thu, 29 June 2006 21:48 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
You may need to sort the files first:
sort file1 > file1a
sort file2 > file2a

Then use comm
comm -23 file1a file2a  # lines that only appear in file1a
comm -13 file1a file2a  # lines that only appear in file2a


Ross Leishman
Re: Unix file comparison [message #180071 is a reply to message #179863] Fri, 30 June 2006 01:58 Go to previous message
Brayan
Messages: 315
Registered: June 2002
Senior Member
Hi Ross Leishman ,

Thankx very much.. it'd worked.

Brayan.
Previous Topic: sqlplus from Unix
Next Topic: Mailx command with Zip Attachment
Goto Forum:
  


Current Time: Mon Nov 30 11:52:54 CST 2020