我有一个包含以下数据的文件
文件名:sample.rcv.gz
数据:
title|currentDate|numberOfLines|
a|ID99900|Paul|Lee|
b|ID99900|New York|7890654|
c|ID99900|Driver|1232423|
a|ID99901|Jim|foo|
b|ID99901|California|1265789|
c|ID99901|Officer|3332424|
a|ID99902|Jean|duval|
b|ID99902|California|9865789|
c|ID99902|Officer|5552424|
a|ID99900|Philips|Chand|
b|ID99900|Delhi|6310654|
c|ID99900|Teacher|7653423|
其中a,b,c是表名。
如何查找同一个表的重复ID?
感谢
答案 0 :(得分:0)
这可以做到:
$ awk -F"|" 'a[$1,$2]++' file
a|ID99900|Philips|Chand|
b|ID99900|Delhi|6310654|
c|ID99900|Teacher|7653423|
如果找到重复数据,您能告诉我如何停止shell吗?至 找到第一个副本时停止/退出进程并回显a 带有重复ID和表名的消息。
示例:重复数据:表A中的ID99900
这可以做到:
$ awk -F"|" 'a[$1,$2]++ {print "Duplicate data: "$2" in table "$1; exit}' file
Duplicate data: ID99900 in table a
答案 1 :(得分:0)
awk -F"|" 'NR!=1{if($1$2 in a)print "Duplicate:",$1,$2;else a[$1$2]}' your_file
下面测试:
> cat temp
title|currentDate|numberOfLines|
a|ID99900|Paul|Lee|
b|ID99900|New York|7890654|
c|ID99900|Driver|1232423|
a|ID99901|Jim|foo|
b|ID99901|California|1265789|
c|ID99901|Officer|3332424|
a|ID99902|Jean|duval|
b|ID99902|California|9865789|
c|ID99902|Officer|5552424|
a|ID99900|Philips|Chand|
b|ID99900|Delhi|6310654|
c|ID99900|Teacher|7653423|
> awk -F"|" 'NR!=1{if($1$2 in a)print "Duplicate:",$1,$2;else a[$1$2]}' temp
Duplicate: a ID99900
Duplicate: b ID99900
Duplicate: c ID99900
>