Convert Lowercase/Uppercase

Kevin FOO
Sep 20, 2024

--

Showing multiple methods to convert a string to lowercase or uppercase.

Parameter expansion

# Convert to lowercase 
a='Hello World';echo ${a,,}

# Convert to uppercase
a='Hello World';echo ${a^^}

awk

# Convert to lowercase
echo 'Hello World' | awk '{print tolower($0)}'

# Convert to uppercase
echo 'Hello World' | awk '{print toupper($0)}'

tr

# Convert to lowercase
echo 'Hello World' | tr '[:upper:]' '[:lower:]'

# Convert to uppercase
echo 'Hello World' | tr '[:lower:]' '[:upper:]'

sed

# Convert to lowercase
echo 'Hello World' | sed 's/.*/\L&/'

# Convert to uppercase
echo 'Hello World' | sed 's/.*/\U&/'

< Back to all the stories I had written

--

--

Kevin FOO
Kevin FOO

Written by Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.

No responses yet