text - Using sed to change only consecutive repeated letters -


using sed, how change letter 'a' 'a' if appears repeated 2 or more consecutive letters. example, from:

galaxy ear aardvak haaaaaaaaa  

into

galaxy ear aardvak haaaaaaaaa  

you can using groups. if have file:

$ cat galaxy ear aardvak haaaaaaaaa  ulaanbaatar 

you can use sed command:

$ sed 's/\(.\)\1\{1,\}/\u&/g' galaxy ear aardvak haaaaaaaaa  ulaanbaatar 

what happen here? if have char, "packed" in group (\(.\)), , group (\1) repeats 1 or more times (\1\{1,\}), replace matched part (&) uppercased version (\u&).


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -