Compare two files and get matching data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare two files and get matching data
# 1  
Old 03-03-2011
Compare two files and get matching data

Hi,

Can anyone help me to compare two files and get the matching data... say i have file1 and file2 ... file1 has 300 unique data with that i need to match with file2 to see how may are matching.. file2 have 1000 records.
# 2  
Old 03-03-2011
Code:
awk 'NR==FNR{a[$0]=1}NR!=FNR&&a[$0]{b++}END{print b} file1 file2

# 3  
Old 03-03-2011
Excellent!! It gives the matching count.. can i get the matching data in display?
# 4  
Old 03-03-2011
Code:
awk 'NR==FNR{a[$0]=1}NR!=FNR&&a[$0]{print $0;b++}END{print "count="b} file1 file2

# 5  
Old 03-03-2011
Code:
grep -f File1 File2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Field matching in two data files

Hello, I am looking to output all of the lines from file2 whose 11th field is present in the first field in file1. Then the second field from file1 should be appended as such: file1: 2222 0.35 4444 0.25 5555 0.75 file2: col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 1111 col1 col2... (4 Replies)
Discussion started by: palex
4 Replies

2. Shell Programming and Scripting

Compare two files and count number of matching lines

Dear All, I would like to compare two files and return the number of matches found. Example File A Lx2 L1_Mus1 L1Md_T Lx5 L1M2 L1_Mus3 Lx3_Mus Lx9 Lx2A L1Md_A L1Md_F2 File B L1_Mus3 L1_Mus3 (3 Replies)
Discussion started by: paolo.kunder
3 Replies

3. Shell Programming and Scripting

Compare and matching column entries in 2 files and

I have 2 files. File 1 has more columns (6 columns but the last column has spaces) than file 2 (file 2 has 4 columns). The entries in file 1 do not change but column 4 in file 2 can be different from the the entry in file 1. I want to create a script that reads in file 1 and then uses column 1 2... (5 Replies)
Discussion started by: kieranfoley
5 Replies

4. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

5. Shell Programming and Scripting

Help to retrieve data from two files matching a string

Hello Experts, I have come back to this forum after a while now, since require a better way to get my result.. My query is as below.. I have 3 files -- 1 Input file, 2 Data files .. Based on the input file, data has to be retreived matching from two files which has one common key.. For EX:... (4 Replies)
Discussion started by: shaliniyadav
4 Replies

6. Shell Programming and Scripting

How to find the matching data b/w 2 files in perl?

Hi friends,, i have find the matching data between 2files. My file1 have a data like rs3001336 rs3984736 rs2840532 File2 have a data like rs3736330 1 2359237 A G 0.28 1.099 0.010 rs2840532 1 2359977 G A 0.363 0.3373 1.123 rs3001336 1 ... (4 Replies)
Discussion started by: sureshraj
4 Replies

7. Programming

How to find the matching data b/w 2 files in perl?

Hi friends,, i have find the matching data between 2files. My file1 have a data like rs3001336 rs3984736 rs2840532 File2 have a data like rs3736330 1 2359237 A G 0.28 1.099 0.010 rs2840532 1 2359977 G A 0.363 0.3373 1.123 rs3001336 1 2365193 G A 0.0812 0.07319 1.12 ... (1 Reply)
Discussion started by: sureshraj
1 Replies

8. Shell Programming and Scripting

compare two columns of different files and print the matching second file..

Hi, I have two tab separated files; file1: S.No ddi fi cu o/l t+ t- 1 0.5 0.6 o 0.1 0.2 2 0.2 0.3 l 0.3 0.4 3 0.5 0.8 l 0.1 0.6 ... (5 Replies)
Discussion started by: vasanth.vadalur
5 Replies

9. Shell Programming and Scripting

compare two files and to remove the matching lines on both the files

I have two files and need to compare the two files and to remove the matching lines from both the files (4 Replies)
Discussion started by: shellscripter
4 Replies

10. Shell Programming and Scripting

compare two files for matching in solaris

I am using solaris, need either awk/shell or perl script to compate two files. both of these file1 and file2 are located in two diffent location path in the same server. file1 location: /export/db/mna file2: /etc/dba The script will compare in file1 first field (e.g. abc00asp)before colon:... (8 Replies)
Discussion started by: amir07
8 Replies
Login or Register to Ask a Question