简体   繁体   中英

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

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 .

If you don't want to use a robust tool specifically intended to find duplicate files, you can use 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 'FNR==NR{seen[$1]++; next} seen[$1]>1' file file
B 2
B 3
C 4
C 5
C 6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM