Capture all the letters which are repeated more than once
Recently i came across a need where i need to fetch all the letters in a line which are repeated more than once in a line contiguously.for example :
lets say there a word "foo bar". I want the letter 'o' in this.
lets say there a word "foo baaar". I want the letters 'o','a' in this.
lets say there a word "foo baaar foo". I want the letters 'o','a' in this again.
Below is code which worked for me:
perl -lne 'push @a,/(\w)\1+/g;END{print @a}' your_file
The above command will scan complete file and prints just the letters that are repeated continguously in the file.
0 comments: