AWK未在记录上重复相同的字段

AWK未在记录上重复相同的字段,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 'BEGIN{FS=OFS=";"}{for(i=1;i<=NF;i++) if($i==a[i]) $i="";else

我想介绍一些数据:

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  'BEGIN{FS=OFS=";"}{for(i=1;i<=NF;i++) if($i==a[i]) $i="";else a[i]=$i }1' file

awk'BEGIN{FS=OFS=“;”}{for(i=1;i您可以使用以下
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
}

你应该尝试添加更多关于这个问题的信息。例如,如何从输入中获得输出。etcAlso它应该只出现在第1、2列,或者可能出现在任何地方?这实际上与我的答案的逻辑相同,但比我早几秒发布。看起来我们的想法完全相同。:)@hek2mgl在同一时间确实有相同的想法:-)唯一的细微区别是
printt
语句在这里被
1
替换,这将触发
awk
中的默认操作,也就是打印整行。
awk -f dedup.awk input.file