awk - Compare two files with first column matching text and 2nd column of first file > than 2nd column value of 2nd file -


looking awk 1 liner:

i have 2 files each 2 columns

i need print records first column match in both files , second file value column > first file value column.

file1

aaaa 322 bbbb 322 dddd 200 

file2

aaaa 700 cccc 400 dddd 100 

looking result

aaaa 700 

appreciate help. far can match column 1 not sure how calculate second value column when it's >

awk 'nr == fnr{a[$1];next}$1 in a' file1.txt file2.txt aaaa 700 dddd 100 

updated

i think may have gotten reversing file order , using:

awk 'fnr==nr{a[$1]=$2 fs $3;next}{ print $0, a[$1]}' file2.txt file1.txt|awk '$3 > $2' |awk '{print $1" "$3}' aaaa 700 

input

[akshay@localhost tmp]$ cat file1 aaaa 322 bbbb 322 dddd 200  [akshay@localhost tmp]$ cat file2 aaaa 700 cccc 400 dddd 100 

output

[akshay@localhost tmp]$ awk 'fnr==nr{a[$1] = $2; next}($1 in a) && $2 > a[$1]' file1 file2 aaaa 700 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -