Unix tr command to convert lower case to upper AND upper to lower case

truffle picture truffle · Apr 20, 2014 · Viewed 21.6k times · Source

So I was searching around and using the command tr you can convert from lower case to upper case and vice versa. But is there a way to do this both at once?

So:

$ tr '[:upper:]' '[:lower:]' or  $ tr A-Z a-z

Will turn "Hello World ABC" to "hello world abc", but what I want is "hELLO wORLD abc".

Answer

Amardeep AC9MF picture Amardeep AC9MF · Apr 20, 2014

This will do what you are looking for:

 tr '[:upper:][:lower:]' '[:lower:][:upper:]'