mawk script to compare 2 files and report where they match

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers mawk script to compare 2 files and report where they match
# 1  
Old 09-14-2009
mawk script to compare 2 files and report where they match

I have two files and would like a report of where they match.

Example of file1:

1 1 1
2 2 2
13 14 15
4 4 4
15 16 17
100 102 1004
56 57 890

Example of file2:

2 2 2
16 10 11
45 22 35
13 14 15
1001 1002 3456
100 102 1004
50 51 52

The desired result is:

13 14 15
100 102 1004

I am looking for the records that are common to each file.


Last edited by vgersh99; 09-14-2009 at 04:20 PM.. Reason: code tags, PLEASE!
# 2  
Old 09-14-2009
nawk 'FNR==NR {f1[$0];next} $0 in f1' file1 file2

not sure why '2 2 2' didn't make it in your sample output........
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Compare data - Match first column and compare second

Hi guys, looking for some help with a way to compare data in two files but with some conditions. example, File 1 consists of site1, site2, site3, File 2 contains site1,l0.1.1.1 site2, site3, site4, I want to be able to match the... (1 Reply)
Discussion started by: mutley2202
1 Replies

2. Shell Programming and Scripting

Compare two files and find match and print the header of the second file

Hi, I have two input files; file1 and file2. I compare them based on matched values in 1 column and print selected columns of the second file (file2). I got the result but the header was not printed. i want the header of file2 to be printed together with the result. Then i did below codes:- ... (3 Replies)
Discussion started by: redse171
3 Replies

3. Shell Programming and Scripting

How to use awk shell script to compare and match two files?

Basically, I have two files dupestest.txt 152,153 192,193,194 215,216 290,291 2279,2280 2282,2283haftest.txt 152,ABBOTS ROAD 153,ABBOTS ROAD 154,ABBOTS ROAD 155,ABBOTS ROAD 156,ABBOTS ROAD 157,ABBOTS ROADI want to find the numbers in dupestest.txt in haftest.txt... (4 Replies)
Discussion started by: amyc92
4 Replies

4. Shell Programming and Scripting

Compare values for a pattern match and execute script

Here in the input file 23:59:13,devicename,21,server1,700 23:59:13,devicename,22,server2,200 23:59:13,devicename,23,server3,200 23:59:13,devicename,24,server4,200 23:59:13,devicename,25,server5,200 23:59:13,devicename,26,server6,200 23:59:13,devicename,27,server7,200... (6 Replies)
Discussion started by: necro98
6 Replies

5. Shell Programming and Scripting

Request to check: compare two files , match same entries, write data before it

Hi all, I have 2 files:Column1 of first file has to be matched with column 3 of second file first file contain DATA like this in 2 columns one with gene name second with whether CAD,HT,RA T2Dor any one column 1 column2 ARFGEF2 CAD DDEF2 CAD PSCD3 CAD PSCD4 CAD CAMK1... (5 Replies)
Discussion started by: manigrover
5 Replies

6. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

7. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

8. Shell Programming and Scripting

Compare two files and mismatch report

Hi I have two files f1 and f2 and comma separated file. I need to comapre two files by field by field and not by whole line. If they match then skip the line from both the files. If they don't match write the mismatch record from f1 to f3. Assume both the files are sorted on first field. ... (5 Replies)
Discussion started by: dgmm
5 Replies

9. Shell Programming and Scripting

Match strings in two files and compare columns of both

Good Morning, I was wondering if anybody could tell me how to achieve the following, preferably with a little commenting for understanding. I have 2 files, each with multiple rows with multiple columns. I need to find each row where the value in column 1 of file 1 matches column 1... (10 Replies)
Discussion started by: GarciasMuffin
10 Replies

10. UNIX for Dummies Questions & Answers

compare two files if doesnt match then display error message

hi , i have one file ,i need to search particular word from this file and if content is matched then echo MATCHED else NOT MATCHED file contains : mr x planned to score 75% in exam but end up with 74%. word to be searched id 75% please help me out . waiting for reply thanks in advance (2 Replies)
Discussion started by: atl@mav
2 Replies
Login or Register to Ask a Question