compare files by lines and columns


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare files by lines and columns
# 1  
compare files by lines and columns

Dear All,

Is it possible to compare 2 files line to line using column values?

for example I have file1:

1;givi;01012000;wer
2;sss;02012000;rrr
3;ccc;03012000;ttt

file 2:

0;uuu;01012000;lll
1;givi;01012000;wer
2;sss;02012000;rrr
3;ccc;03012000;ttt
5;givi;01012000;hhh

I want to get only lines from file2 where combination of 2nd and 3rd columns do not exist in file 1. it means that one line from file2 shuld compare to all lines in file1?????

Thanks in advance.

Givi
# 2  
Try...
Code:
awk -F';' 'BEGIN{while(getline<"file1") a[$2,$3]=1};a[$2,$3]!=1' file2

# 3  
Thank you very much.
Exactly I wanted.
# 4  
help needed

Hello all awk masters.

i have query but i need add some change and i don't know how.
my current awk program is :
Code:
nawk -F"~" -f m.awk file1

m.awk:
BEGIN {
while(getline<"file2")
arr[$1,$7]=1
}
arr[$1,$7]!=1 {print }

additionaly i need to change $2 from file1 to $2 from file2
so display is line from file1 with $2 from file2

Thanks in advance.
Peter

Last edited by vbe; 07-12-2011 at 07:31 AM..
# 5  
Hello Ygor,

Would you please explain what that does

a[$2,$3]=1};a[$2,$3]!=1' from your previous post. I am trying to digest this code.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #518
Difficulty: Medium
Neither integer nor floating point numbers can represent every possible number since they use a finite number of bits to represent the number.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to compare two columns in two files?

Hi All, I have a.dat file with content 1,338,30253395122015103,2015103,UB0085000,STMT151117055527002,,, 1,338,30253395122015103,2015103,UB0085000,STMT151117055527001,,, and b.dat having content 1,STMT151117055527001,a1.txt,b1.txt,c1.txt 1,STMT151117055527002,a2.txt,b2.txt,c2.txt ... (13 Replies)
Discussion started by: PRAMOD 96
13 Replies

2. UNIX for Dummies Questions & Answers

Help need to compare columns in files

Hi, Below is my requirement file1 id|cnt 1|1 2|2 3|3 file2 id_1|cnt_1 1|1 2|1 3|1 I want to compare cnt and cnt_1 columns, if they are differ then give the details Am using below awk command, but the output is not as expected. (2 Replies)
Discussion started by: grandhirahuletl
2 Replies

3. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

4. Shell Programming and Scripting

Compare Columns of two files

Hi I have file 1 like this and file 2 like this I need to compare column 3 of both files and delete lines in file1 with same column 3 values in two files. So the output is I tried with perl but didnt work. A perl code will be good as I am learning the language, but any other code would... (1 Reply)
Discussion started by: polsum
1 Replies

5. Shell Programming and Scripting

Compare files by lines and columns

Inspired by the extremely short awk code from Ygor on this post I wanted to compare two files on only one field. I can't get it to work. Can anybody help on explaining the code and fix the code? My code which does not work: awk 'BEGIN{a=1};a!=1' file1.txt file2.txt >outfile.txt file1.txt... (1 Reply)
Discussion started by: sdf
1 Replies

6. UNIX for Dummies Questions & Answers

Compare Columns in two files

Hi all, I would like to compare a column in one file to a column in another file and when there is a match it prints the first column and the corresponding second column. Example File1 ABA ABC ABE ABF File 2 ABA 123 ABB 124 ABD 125 ABC 126 So what I would like printed to a file... (0 Replies)
Discussion started by: pcg
0 Replies

7. Shell Programming and Scripting

How to compare 2 files & get only few columns based on a condition related to both files?

Hiiiii friends I have 2 files which contains huge data & few lines of it are as shown below File1: b.dat(which has 21 columns) SSR 1976 8 12 13 10 44.00 39.0700 70.7800 7.0 0 0.00 0 2.78 0.00 0.00 0 0.00 2.78 0 NULL ISC 1976 8 12 22 32 37.39 36.2942 70.7338... (6 Replies)
Discussion started by: reva
6 Replies

8. Shell Programming and Scripting

How to compare two columns in two files?

Hello all, Could someone please let me know shell script or awk solution to compare two columns in two files? Here is the sample - file1.txt abc/xyz,M1234 ddd/lyg,M2345 cnn/tnt,G0123 file2.txt A,abc/xyz,kk,dd,zz,DCT,G0123,1 A,ddd/lyg,kk,dd,zz,DCT,M1234,1... (17 Replies)
Discussion started by: sncoupons
17 Replies

9. Shell Programming and Scripting

Compare few columns from two files

My Friends, Need your help to find the difference between few columns from two comma delimited files. For example, File1 and File2 has 22 columns, and I want to find the difference in first 12 columns. I have list of file names in MyListOfFiles2Compare.txt. Data is separated with commas.... (5 Replies)
Discussion started by: manish44
5 Replies

10. UNIX for Dummies Questions & Answers

find common lines using just one column to compare and result with all columns

Hi. If we have this file A B C 7 8 9 1 2 10 and this other file A C D F 7 9 2 3 9 2 3 4 The result im looking for is intersection with A B C D F so the answer here will be (10 Replies)
Discussion started by: alcalina
10 Replies

Featured Tech Videos