[英]bash print complete lines where just the first n characters match
I have created a sorted list of hashes for certain files 我为某些文件创建了哈希排序列表
ffb01af8fda1e5c3b74d1eb384d021be1f1577c3 *./Pictures/camera/London 170713/P9110042.JPG
ffb01af8fda1e5c3b74d1eb384d021be1f1577c3 *./Pictures/london/P9110042.JPG
where there are duplicate hashes (just the hashes), I want to print the whole line of all matches 在有重复的哈希(只是哈希)的地方,我想打印所有匹配项的整行
so say there where hashes ABC 所以说那里有哈希ABC
A 1
B 2
B 3
C 4
C 5
C 6
in this example all the lines except the first one should be printed 在此示例中,除第一行外,所有行均应打印
B 2
B 3
C 4
C 5
C 6
Before you continue, look up fdupes
. 在继续之前,请查找
fdupes
。
If you don't want to use a robust tool specifically intended to find duplicate files, you can use sort | uniq
如果您不想使用专门用于查找重复文件的强大工具,则可以使用
sort | uniq
sort | uniq
: sort | uniq
:
$ cat file
A 1
B 2
B 3
C 4
C 5
C 6
$ sort file | uniq -w 1 -D
B 2
B 3
C 4
C 5
C 6
Using awk you can do (will work with unsorted file also): 使用awk可以做到(也可以使用未排序的文件):
awk 'FNR==NR{seen[$1]++; next} seen[$1]>1' file file
B 2
B 3
C 4
C 5
C 6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.