开发者

Awk, compare 2 files and write out incomparables

I usually use

awk BEGIN {FS=" "} NR==FNR{arry[$1]=$0; next} $1 in array && $0=arr[$1] FS in fields infile1 infile2 > outfile 

to extra开发者_开发技巧ct common fields in 2 files based on field of interest. But this time I need incomparables. I have 2 files with equal lines but 200 lines in the second file do not have the same coding as in file1.

I tried to :

paste f1 f2 | sort -n -k1,2

by both fields hoping to get $1==$2 and take unequal fields but I don't get $1==$2 even when there should be.

How can I do this?


Since you seems to compare by the first field and since I don't know what your data files look like, I am going to blindly attempt at this:

$ cat data1.txt
dana 100
john 101
fiona 102

$ cat data2.txt
dana 100
john 501
fiona 102

$ cat data[12].txt|sort|uniq -u
john 101
john 501

The above solution will prints out lines that are not the same, based on the first field. Since I don't fully understand your data file, I am going ask this question. Does the following solve your problem?

diff data1.txt data2.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜