Computing.Net > Forums > Unix > Compare Fields in two Files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Compare Fields in two Files

Reply to Message Icon

Name: passiton
Date: September 28, 2005 at 05:32:22 Pacific
OS: Unix
CPU/Ram: P4-Intel and 512mb
Comment:

Can anyone help me with shell script to this problem.

I have two files as shown below. I want to loop through the two files by comparing column1, row1 in file1 with column1, row1 in file2, then column2, row1 in file1 with column2, row1 in file2, and so on till the end of the two files. If there is any difference in the individual “item” in each row, my script should be able to print/write it to a file say file3.


file1

Computers 2.84 49
Printers 1.56 65
Keyboard 1.52 22
Mouse 1.24 35
Webcam 3.99 74

file2

Scanners 5.86 49
Printers 1.56 88
Keyboard 1.52 22
Plotters 3.28 56
TV Cards 6.24 67



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 28, 2005 at 23:12:20 Pacific
Reply:

so what should file 3 look like? I'm interpreting that you want to compare line 1 in file 1 with line 1 in file2 , line 2 with file 1 with line 2 in file 2, etc.

Please advise.


0

Response Number 2
Name: passiton
Date: September 29, 2005 at 15:12:06 Pacific
Reply:

The file3 should list all the lines that match the comparison. I want to compare column1, row1 ( say computer) in file1 with column1, row1 ( scanners)in file2 and if they match i write line in file2 to file3 (I am comparing column wise, not the entire line of file1 to that of file2).



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Compare Fields in two Files

replacing fields in delimited file www.computing.net/answers/unix/replacing-fields-in-delimited-file/6463.html

Find un-match in two files www.computing.net/answers/unix/find-unmatch-in-two-files-/8105.html

compare two files field string www.computing.net/answers/unix/compare-two-files-field-string/8078.html