awk print non matching lines based on column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk print non matching lines based on column
# 1  
Old 08-08-2011
awk print non matching lines based on column

My item was not answered on previous thread as code given did not work

I wanted to print records from file2 where comparing column 1 and 16 for both files find rows where column 16 in file 1 does not match column 16 in file 2

Here was CODE give to issue



Code:
~/unix.com$ cat f1
123456789~col2~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~10/15/10
234567891~col2~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~12/22/11
345678912~col2~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~04/22/14
456789123~col2~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~11/19/12
567891234~col2~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~01/07/11
678912345~col2~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~12/07/10
~/unix.com$ cat f2
123456789~col2b~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~10/15/10
123456789~col2b~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~12/22/11
345678912~col2b~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~04/22/14
456789123~col2b~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~11/19/12
567891234~col2b~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~01/07/11
567891234~col2b~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~12/07/10
~/unix.com$ awk -F~ 'NR==FNR{A[NR]=$1$16;next}$1$16!=A[FNR]' f1 f2
123456789~col2b~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~12/22/11
567891234~col2b~col3~col4~col5~col6~col7~col8~col9~col10~col11~col12~col13~col14~col15~12/07/10



I also tried to hunt for another solution and found something that would give me the matching rows but could not find the opposite.

Code:
 
awk -F"~" 'FILENAME=="f1"{A[$1$16]=$1$16} FILENAME=="f2"{if(A[$1$16]){print}}' f1 f2

Please assist in tweaking either code to have it work

Thank you

Moderator's Comments:
Mod Comment No double posting. Continued here

Last edited by pludi; 08-08-2011 at 06:07 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print lines based on text in field and value in two additional fields

In the awk below I am trying to print the entire line, along with the header row, if $2 is SNV or MNV or INDEL. If that condition is met or is true, and $3 is less than or equal to 0.05, then in $7 the sub pattern :GMAF= is found and the value after the = sign is checked. If that value is less than... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

awk to select lines with maximum value of each record based on column value

Hello, I want to get the maximum value of each record separated by empty line based on the 3rd column of each row within each record? Input: A1 chr5D 634 7 82 707 A2 chr5D 637 6 82 713 A3 chr5D 637 5 82 713 A4 chr5D 626 1 82 704... (4 Replies)
Discussion started by: yifangt
4 Replies

3. Shell Programming and Scripting

awk to print matching lines in files that meet critera

In the tab delimited files below I am trying to match $2 in file1 to $2 of file2. If a match is found the awk checks $3 of file2 and if it is greater than 40% and $4 of file2 is greater than 49, the line in file1 is printed. In the desired output line3 of file1 is not printed because $3 off file2... (9 Replies)
Discussion started by: cmccabe
9 Replies

4. UNIX for Dummies Questions & Answers

awk - Print lines if only matching key is found

I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. Thanks a lot. Any help is appreciated. Script I am using: awk 'FNR == NR && ! /^]*$/ {... (9 Replies)
Discussion started by: High-T
9 Replies

5. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. UNIX for Dummies Questions & Answers

awk solution to duplicate lines based on column

Hi experts, I have a tab-delimited file with one column containing values separated by a comma. I wish to duplicate the entire line for every value in that comma-delimited field. For example: $cat file 4444 4444 4444 4444 9990 2222,7777 6666 2222 ... (3 Replies)
Discussion started by: torchij
3 Replies

7. Shell Programming and Scripting

Based on column in file1, find match in file2 and print matching lines

file1: file2: I need to find matches for any lines in file1 that appear in file2. Desired output is '>' plus the file1 term, followed by the line after the match in file2 (so the title is a little misleading): This is honestly beyond what I can do without spending the whole night on it, so I'm... (2 Replies)
Discussion started by: pathunkathunk
2 Replies

8. UNIX for Dummies Questions & Answers

Removing Lines based on matching first column

I have a file1 that looks like this: File 1 a b b c c e d e and a file 2 that looks like this: File 2 b c e e Note that file 2 is the right hand column from file1. I want to remove any lines from file1 that begin with the column in file2. In this case the desired output... (6 Replies)
Discussion started by: kschiltz55
6 Replies

9. Shell Programming and Scripting

awk to print lines based on string match on another line and condition

Hi folks, I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and... (5 Replies)
Discussion started by: rowie718
5 Replies

10. Shell Programming and Scripting

Print lines matching value(s) in other file using awk

Hi, I have two comma separated files. I would like to see field 1 value of File1 exact match in field 2 of File2. If the value matches, then it should print matched lines from File2. I have achieved the results using cut, paste and egrep -f but I would like to use awk as it is efficient way and... (7 Replies)
Discussion started by: SBC
7 Replies
Login or Register to Ask a Question