How do I filter or retain duplicates in Perl?
- by manu
I have one text string which is having some duplicate characters (FFGGHHJKL). These can be made unique by using the positive lookahead:
$ perl -pe 's/(.)(?=.*?\1)//g']
For example, with "FFEEDDCCGG", the output is "FEDCG".
My question is how to make it work on the numbers (Ex. 212 212 43 43 5689 6689 5689 71 81 === output should be 212 43 5689 6689 71 81) ? Also if we want to have only duplicate records to be given as the output from a file having n rows
212 212 43 43 5689 6689 5689 71 81
66 66 67 68 69 69 69 71 71 52
..
Output:
212 212 43 43 5689 5689
66 66 69 69 69 71 71
How can I do this?