Reputation: 23
How do you delete words in a string in BASH that have capital letters? Ex.
Input:
Taco burrito Mexico fiesta
Output:
burrito fiesta
The solution I saw on Stack Overflow doesn't work for me since the linux machine I'm working with doesn't accept the -r
switch.
Upvotes: 2
Views: 501
Reputation: 8406
Pure bash
:
set -- Taco burrito Mexico fiesta ; LC_ALL=C; echo ${@/*[A-Z]*}
Or:
a=(Taco burrito Mexico fiesta) ; LC_ALL=C; echo ${a[@]/*[A-Z]*}
Output (of either):
burrito fiesta
Upvotes: 0
Reputation: 246877
For fun, perl
perl -aE 'say "@{[ grep {not /^[[:upper:]]/} @F ]}"' file
Upvotes: 1
Reputation: 16968
$ echo Taco burrito Mexico fiesta | awk '{gsub(/ (\S*[A-Z]\S*)|(\S*[A-Z]\S* )/, "")}1'
burrito fiesta
Upvotes: 0
Reputation: 785286
You may use this sed
:
s='Taco burrito Mexico fiesta'
sed 's/[[:upper:]][^[:blank:]]*[[:blank:]]*//g' <<< "$s"
burrito fiesta
Details:
[[:upper:]]
: Matches an uppercase letter[^[:blank:]]
: Matches any character except a space or tab character[[:blank:]]
: Matches a space or tab characterUpvotes: 1