matching 2 exact fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching 2 exact fields
# 1  
Old 11-13-2008
matching 2 exact fields

Dear experts,

I have a file1 that looks like

Code:
60127930928 2091
60129382039 2092
60126382937 2091
60128937928 2061
60127329389 2062
60123748730 2061
60128730293 2061

and file 2 that looks like

Code:
60127930928 2091
60129382039 2092
60126382937 2093
60128937928 2061
60127329389 2063
60123748730 2061
60128730293 2061

In both files, i need to match the 2 fields exactly (separated by space) and output the lines in file2 that does not match file1. For example, the output for the 2 files above should be

Code:
60126382937 2093
60127329389 2063

Ive tried using "join" but i cant match 2 fields. Please help !
# 2  
Old 11-14-2008
comm -13 file1 file2 should do it.

comm normally outputs 3 columns... the lines in file1 only, the lines in file2 only, and the lines that are in both. The -1 and -3 suppress the output of the 1st and 3rd columns, so you are just left with the lines that are in file2 only.
# 3  
Old 11-14-2008
Thanks annihilannic. Great
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two files by two matching fields

Long time listener first time poster. Hope someone can advise. I have two files, 1000+ lines in each, two fields in each file. After performing a sort, what is the best way to find exact matches where field $1 and $2 in file1 are also present in file2 on the same line, then output only those... (6 Replies)
Discussion started by: bstaff
6 Replies

2. Shell Programming and Scripting

sed - Exact pattern matching and replace

Hi Team, I am facing a problem as under, Suppose I have a file (test.txt) with the below content (all braces and slashes are included in the contents of the file) Now I want to append few words below matched line, I have written the below sed: sed '/option/a insert text here' test... (2 Replies)
Discussion started by: ankur328
2 Replies

3. Shell Programming and Scripting

Convert text between exact matching patterns to Title case

Hi Folks, I have a large text file with multiple similar patterns on each line like: blank">PATTERN1 some word PATTERN2 title=">PATTERN1 some word PATTERN2 blank">PATTERN1 another word PATTERN2 title=">PATTERN1 another word PATTERN2 blank">PATTERN1 one more time PATTERN2 title=">PATTERN1... (10 Replies)
Discussion started by: martinsmith
10 Replies

4. Shell Programming and Scripting

Matching multiple fields from two files and then some?

Hi, I am working with two tab-delimited files with multiple columns, formatted as follows: File 1: >chrom 1 100 A G 20 …(10 columns) >chrom 1 104 G C 18 …(10 columns) >chrom 2 28 T C ... (4 Replies)
Discussion started by: mbp
4 Replies

5. Shell Programming and Scripting

sed to exact matching a word in free BSD

Hi, Thanks for looking at this issue. I have many words/lines in a files like below apple pine apple custored apple apple apple if i want to replace only/exact apple occurrences with XXX i could use below, sed 's/\<apple\>/XXX/g' filename this is working in Linux, but now in my free BSD... (3 Replies)
Discussion started by: ramanaraoeee
3 Replies

6. Shell Programming and Scripting

Select the exact matching contents using grep

Hi everyone I've two files.. The contents of file1 are as shown below 4 5 12 13 36 37 45 46 47 The contents of file2 are as shown below 21 hello 13 world (5 Replies)
Discussion started by: abk07
5 Replies

7. UNIX for Dummies Questions & Answers

Matching exact string with blank space using grep

hi! i'm trying to get grep to do an exact match for the following pattern but..it's not quite working. I'm not too sure where did I get it wrong. any input is appreciated. echo "$VAR" | grep -q '^test:]name' if ; then printf "test name is not found \n" fi on... (4 Replies)
Discussion started by: jazzaddict
4 Replies

8. Linux

matching two fields

Hi I am having 2 fields and if f1=f2 i wanna print that line eg 1 2 1 3 1 9 2 2 3 5 9 9 In the abov eg. the highlighted lines shud be printed 2 2 9 9 Thanking u (3 Replies)
Discussion started by: binnybio
3 Replies

9. Shell Programming and Scripting

Matching by key fields

I have a file (key.dat) that contains two columns: AA|1234| BB|567| CC|8910| I have another file (extract.dat) that contains some data: SD|458|John|Smith| AA|3345|Frank|Williams| AA|1234|Bill|Garner| BD|0098|Yu|Lin| BB|567|Gail|Hansen| CC|8910|Ken|Nielsen| I want to compare the... (5 Replies)
Discussion started by: ChicagoBlues
5 Replies

10. Shell Programming and Scripting

Matching fields of rows and then operating

Hi All, I was seaching for script for solaris 5.10 environmet to get a output file from Input file like this. INPUT FILE---------------- 1000KE,MINE,74748 1000KE,YOUR,123998 200KE,MINE,886049 50KE,MINE,474176 50KE,YOUR,379998 100KE,YOUR,999994 50KE,MINE,9601 50KE,YOUR,990393... (3 Replies)
Discussion started by: ashis.tewari
3 Replies
Login or Register to Ask a Question