Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find lines in file that contain duplicate characters

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!

like image 902
Jen Avatar asked Dec 15 '22 15:12

Jen


1 Answers

grep '\(.\).*\1' file.txt

Matches any line that contains a character, any string, and then that same character, i.e. any line with duplicates.

like image 150
that other guy Avatar answered Dec 28 '22 10:12

that other guy