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

Compare Fields in two Files

Reply to Message Icon

Original Message
Name: passiton
Date: September 28, 2005 at 05:32:22 Pacific
Subject: Compare Fields in two Files
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


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: September 28, 2005 at 23:12:20 Pacific
Subject: Compare Fields in two Files
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 2
Name: passiton
Date: September 29, 2005 at 15:12:06 Pacific
Subject: Compare Fields in two Files
Reply: (edit)

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).



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Compare Fields in two Files

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge