Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 从三列文件中删除重复记录_Linux_Shell_Awk - Fatal编程技术网

Linux 从三列文件中删除重复记录

Linux 从三列文件中删除重复记录,linux,shell,awk,Linux,Shell,Awk,我试图从包含3列的txt文件中删除一些条目。前两个包含ID条目,第三个包含其百分比,如下所示: ID#3 ID#1 100.00 ID#4 ID#4 40.00 ID#4 ID#5 33.065 ID#5 ID#5 100.000 ID#5 ID#4 33.065 ID#6 ID#6 100.000 我希望“删除”具有相同ID的每个条目,但仅当百分比为100%时,以便所需的输出如下: ID#3 ID#1

我试图从包含3列的txt文件中删除一些条目。前两个包含ID条目,第三个包含其百分比,如下所示:

ID#3    ID#1    100.00
ID#4    ID#4    40.00
ID#4    ID#5    33.065
ID#5    ID#5    100.000    
ID#5    ID#4    33.065
ID#6    ID#6    100.000
我希望“删除”具有相同ID的每个条目,但仅当百分比为100%时,以便所需的输出如下:

ID#3    ID#1    100.00    
ID#4    ID#4    40.00
ID#4    ID#5    33.065
ID#5    ID#4    33.065
我试过这个:

cat file.txt | awk '$3!=100.0 && $1=$2 {print $1,$2}'

但我找不到一种方法来包含前两列不相同的情况

你能试试下面的吗

awk '($1==$2) && $NF==100{next} 1' Input_file
解释:添加上述代码的详细解释

awk '                       ##Starting awk program from here.
($1==$2) && $NF==100{       ##Checking condition if $1(first field) equals to $2(2nd field) AND $NF(last field) equals 100 then do following.
  next                      ##next will SKIP all further statements from here.
}                           ##Closing BLOCK for above condition here.
1                           ##Mentioning 1 will print edited/non-edited lines here.
' Input_file                ##Mentioning Input_file name here.
  • $1==$2
    检查第一列是否与第二列相同
  • $3==100
    检查第三列是否为
    100
  • &&
    检查上述两个条件是否均为真
  • !($1==$2&&$3==100)
    以反转组合条件
  • 也可以使用
    $1=$2 || $3!=100
    (请参阅)

还要注意,文件可以直接传递给
awk
命令。并且不确定当显示的预期输出包含三列时为什么要使用
{print$1,$2}

首先,感谢您的及时回复。不幸的是,这不是我想要的。您建议的输出是$1=$2=100.00。我要找的是从我的文件中删除格式为$1=$2=100.00的所有条目。@KGee,我也为上述代码添加了详细的解释,以防有任何疑问。
$ awk '!($1==$2 && $3==100)' ip.txt
ID#3    ID#1    100.00
ID#4    ID#4    40.00
ID#4    ID#5    33.065
ID#5    ID#4    33.065