相同的领域,我想提出一些类型的数据:AWK不重复的记录
A;01;data_1;CP
A;01;data_15;aP
A;01;data_23;Com
A;01;data_106;id
这样
A;01;data_1;CP
;;data_15;aP
;;data_23;Com
;;data_106;id
有没有一种简单的方法使用awk做到这一点?
任何帮助表示赞赏!
相同的领域,我想提出一些类型的数据:AWK不重复的记录
A;01;data_1;CP
A;01;data_15;aP
A;01;data_23;Com
A;01;data_106;id
这样
A;01;data_1;CP
;;data_15;aP
;;data_23;Com
;;data_106;id
有没有一种简单的方法使用awk做到这一点?
任何帮助表示赞赏!
您可以使用下面的脚本awk
:
# dedup.awk
BEGIN {
# Setting input and output delimiter to ';'
FS=OFS=";"
}
{
# Iterate trough all fields
for(i=1;i<NF+1;i++) {
# If the previous record's field at this index has
# the same value as this field then set this field
# to an empty string
if(p[i]==$i) {
$i=""
} else {
# Otherwise update the array that keeps
# information about the previous record(s)
p[i] = $i
}
}
# Print the record
print
}
您可以执行这样的:
awk -f dedup.awk input.file
你应该尝试添加有关问题的更多信息。例如。如何从输入中获得输出。 etc – nu11p01n73R
此外,它预计仅列1,2或可能在任何地方? – Inian