frodo
frodo

Reputation: 1063

Delete words with capital letters

I am trying to delete all words that start with capital letters but below is just catching "Al" from the first word:

echo "Always baby Yeah" | sed -r 's/^([AEIOU].)//g'

How do I capture just all the words starting with capital letters?

Upvotes: 0

Views: 1332

Answers (3)

jaypal singh
jaypal singh

Reputation: 77105

This regex should work \b[A-Z](\w*)\b

[jaypal:~/Temp] echo "Always baby Yeah" | sed -r 's/\b[A-Z](\w*)\b//g'
 baby 

Upvotes: 0

prashanth
prashanth

Reputation: 161

below regex should be helpful for you

m/(^[A-Z]\w*)/

Upvotes: 0

Karoly Horvath
Karoly Horvath

Reputation: 96266

You only remove the first two characters and only if they are at the start of the string.

Use: sed -r 's/\b[A-Z]\w*//g' or 's/\b[A-Z]\w*\s*//g' if you want to remove the whitespace too.

Upvotes: 2

Related Questions