Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two Files to Compare and no Match results in 3 File 1

Status
Not open for further replies.

aoroca

IS-IT--Management
Oct 3, 2003
39
CO
need your help about a script I wish do. I have 2 dynamic files (file1 and file2, like a little Data Base), and its important compare this files and get a file3 with your differences, for example:_

FILE1 DB TO COMPARE

5851388
5859999
4164754
6123574
3214587

FILE2 RAW INPUT
9874563 The number calling is 111
5851388 The number calling is OK
6237733 the number is wrong
5859999 The number calling is ok

Then if You compare this 2 files (BD Dynamics – Files updated periodically), FILE1 passed from beginning to EOF and compare all datas with FILE2 generating the FILE3 as:


FILE3 DESIRED OUTPUT
9874563 The number calling is 111
6237733 the number is wrong

When FILE1 data match with FILE2, the data matched in FILE2 are deleted and copy in FILE3

I don’t know how do it? I appreciate your information ASAP.

Regards,



 
What operating system are you using?

On Solaris:

[tt]/usr/xpg4/bin/grep -vf file1 file2 > file3[/tt]

Some versions of grep do not support the -f option.

Annihilannic.
 
My friend, very simple... Thanks a lof for timely information. best regards.
 
Annihilannic,

Say for example I have two files which I am trying to compare. I know 1 file has about 100 more lines than the other. What is the difference between 'grep -ivf file1 file2 > file3'

and

'grep -ivf file2 file1 > file3'?

I initially tried using:

for server in `cat list3.out`
do
grep -iv $server list2.out >> listchk.out
done

which obviously would not work. What is the best solution for determining which lines are missing in the files? Any help would be greatly appreciated.

Thanks,

John

 
I'd say diff would be more appropriate for that situation.

The -f <file> option to grep means to use that file as a list of expressions to search for in the standard input, or in this case, the files specified on the command line.

So by reversing file1 and file2 you are simply using a different list of expressions to search for, and searching for them in a different file.... I hope that makes sense!

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top