13

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".

Pablo Bianchi
  • 1,824
  • 1
  • 26
  • 30
truffle
  • 455
  • 1
  • 9
  • 17

3 Answers3

14

This will do what you are looking for:

 tr '[:upper:][:lower:]' '[:lower:][:upper:]'
Amardeep AC9MF
  • 18,464
  • 5
  • 40
  • 50
4

I think tr '[a-zA-Z]' '[A-Za-z]' is more straight forward, and easier to remember.

dvorak4tzx
  • 493
  • 7
  • 8
1

You can use \L& and \U& to convert to lower and upper case respectively:

$echo "SUJIT dhamale " | sed 's/.*/\L&/g'

Result: sujit dhamale

$ echo "SUJIT dhamale " | sed 's/.*/\U&/g'

Result: SUJIT DHAMALE

Laurel
  • 5,965
  • 14
  • 31
  • 57
Sujit Dhamale
  • 1,311
  • 11
  • 14