Reputation: 445
I'd like to convert a string from upper to lower case. I know there are different ways of solving this problem, but I'd like to understand why this command doesn't work:
echo "aa" | sed 's/'[:upper:]'/'[:lower:]'/g'
Is it a wrong way to use the classes of characters?
Upvotes: 2
Views: 2705
Reputation: 3838
Another possible solution with gawk :
[ ~]$ echo "HELLO"|awk '{print tolower($0)}'
hello
Upvotes: 0
Reputation: 8281
from lowercase to uppercase, you can use
echo "aW123bR" | sed -r 's/[a-z]+/\U&/g'
tr
command is an interesting alternative
echo "aW123bR" | tr '[:lower:]' '[:upper:]'
Upvotes: 6
Reputation: 782624
In sed
, the y
command is used for mapping sets of characters:
sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
It requires a literal list of characters, not character classes.
Upvotes: 1