我不想根据第6列和第7列打印重复的行。sort -u
似乎无济于事
cat / tmp / testing:-
-rwxrwxr-x. 1 root root 52662693 Feb 27 13:11 /home/something/bin/proxy_exec
-rwxrwxr-x. 1 root root 27441394 Feb 27 13:12 /home/something/bin/keychain_exec
-rwxrwxr-x. 1 root root 45570820 Feb 27 13:11 /home/something/bin/wallnut_exec
-rwxrwxr-x. 1 root root 10942993 Feb 27 13:12 /home/something/bin/log_exec
-rwxrwxr-x. 1 root root 137922408 Apr 16 03:43 /home/something/bin/android_exec
当我尝试cat /tmp/testing | sort -u -k 6,6 -k 7,7
时,我得到:-
-rwxrwxr-x. 1 root root 137922408 Apr 16 03:43 /home/something/bin/android_exec
-rwxrwxr-x. 1 root root 52662693 Feb 27 13:11 /home/something/bin/proxy_exec
期望的输出如下,因为这是唯一根据月和日期列与其他文件不同的文件
-rwxrwxr-x. 1 root root 137922408 Apr 16 03:43 /home/something/bin/android_exec
答案 0 :(得分:0)
在gnu sed上尝试
sed -E '/^\s*(\S+\s+){5}Feb\s+27/d' testing
在gnu awk上尝试
awk 'NR==1{a=$6$7;next} a!=$6$7{print}' testing
答案 1 :(得分:0)
[not]使用awk打印基于第6列和第7列的重复行,您可以:
$ awk '
++seen[$6,$7]==1 { # count seen instances
keep[$6,$7]=$0 # keep first seen ones
}
END { # in the end
for(i in seen)
if(seen[i]==1) # the ones seen only once
print keep[i] # get printed
}' file # from file or pipe your ls to the awk
给定输入的输出:
-rwxrwxr-x. 1 root root 137922408 Apr 16 03:43 /home/something/bin/android_exec
通知:关于解析ls
输出的所有标准警告仍然适用。