Using sed, how to change the letter ‘a’ to ‘A’ but only if it appears repeated as two or more consecutive letters. Example, from:
galaxy
ear
aardvak
Haaaaaaaaa
into
galaxy
ear
AArdvak
HAAAAAAAAA
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do it using groups. If you have this file:
You can use this sed command:
What does happen here? If we have a char, “packed” in a group (
\(.\)), and this group (\1) repeats itself one or more times (\1\{1,\}), then replace the matched part (&) by its uppercased version (\U&).