如何比较unix中一个文件的列

时间:2012-09-07 09:13:49

标签: unix sed awk

我有一个文件File_1.txt

AA:BB:CC 
a@gmail.comb@gmail.com:c@yahoo.co.in -------------------------- Row1 
x@rediff.com,y@gmail.com:y@yahoo.in:z@redhat@com ---------------Row2
a@yahoo.in,c@gmail.com:b@yahoo.co.in,a@rediff.com:c@uix.xo.in---Row3

此处AABBCC为三列,文件为:分隔。

在第1行中,如果AA数据与BB AACC {匹配使用BB数据{1}}然后打印CC,如果没有,则打印Row 1 matched

2 个答案:

答案 0 :(得分:2)

$ gawk -F: 'FNR > 1 {if ($1 == $2 || $1 == $3 || $2 == $3)
                       print FNR, "match";
                     else
                       print FNR, "no match";}' < File_1.txt

答案 1 :(得分:0)

awk -F: '{if(!($1==$2||$2==$3||$3==$1))printf("%s","not ");print"matched",$0}' file

测试如下:

> cat temp
AAAA:0:12
BBBBB:2:2
CCCCC:1:1
DDDD:0:0
EEEEE:1:2
> awk -F: '{if(!($1==$2||$2==$3||$3==$1))printf("%s","not ");print"matched",$0}' temp
not matched AAAA:0:12
matched BBBBB:2:2
matched CCCCC:1:1
matched DDDD:0:0
not matched EEEEE:1:2