比较第一列和第二列,并在shell脚本中取出第二列中不是uniq的值

时间:2016-04-07 07:35:12

标签: linux shell

比较第一列和第二列,并在shell脚本中取出第二列中不是uniq的值。

示例输入:

58811051802414,50064179170,0000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06

58811051802414,50064179170,0000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06

70128031244580,50064178465,1000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06

70128031244580,50064178255,1000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06

所需的输出:

58811051802414,50064179170,0000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06

70128031244580,50064178465,1000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06

70128031244580,50064178255,1000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06

我们需要查看第一列值是uniq并与同一文件的第二列进行比较,如果uniq打印该值,我们需要省略重复项并仅打印uniq值。

第二次修改。

70128031244580,50064178465,1000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06

70128031244580,50064178255,1000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06

这两个第一列有不同的第二列,我们需要将其打印为

70128031244580,Found 2 different values. 

1 个答案:

答案 0 :(得分:0)

$ awk -F, '!a[$1,$2]++' file 58811051802414,50064179170,0000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06 70128031244580,50064178465,1000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06 70128031244580,50064178255,1000,TEREAE,20160630,TESTIIII,,,,20130628T04:30:06 救援!

$ awk -F, '!a[$1,$2]++' file | 
  awk -F, '{a[$1]++} END{for(k in a) if(a[k]>1) print k, "Found " a[k] " values"}'

70128031244580 Found 2 values

将此管道连接到第二个脚本

python -m webbrowser "http://www.example.com/"