问题
I need some help in locating lines in a text file that contain duplicate characters. I prefer using bash, but any other method will do fine :)
A small example just to make things clear:
file.txt:
1234
11234
abcd
12234
ab321
1233
zs11w
12w2
the desired output:
11234
12234
1233
zs11w
12w2
Thanks for all your help!
回答1:
grep '\(.\).*\1' file.txt
Matches any line that contains a character, any string, and then that same character, i.e. any line with duplicates.
回答2:
Perl:
perl -ne 'print if /(.)\1/' file.txt
awk:
awk -F "" '{for (i=1; i<NF; i++) if ($i == $(i+1)) {print; next}}' flie.txt
来源:https://stackoverflow.com/questions/14223350/find-lines-in-file-that-contain-duplicate-characters