Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

unix

tr

pipeline

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

like image 872
truffle Avatar asked Apr 20 '14 05:04

truffle


People also ask

Which of the tr command translate the lower case to upper case?

You can use `tr` command in the following way also to convert any string from lowercase to uppercase. Run the following command to convert all small letters of the string,'linuxhint' into the capital letter. Output: The following output will appear after executing the above command.

How do you change uppercase to lowercase in UNIX?

How do I convert uppercase words or strings to a lowercase or vise versa on Unix-like / Linux bash shell? Use the tr command to convert all incoming text / words / variable data from upper to lower case or vise versa (translate all uppercase characters to lowercase).

Which of these tr command translates the lower case letters to capital letters in the give string Mcq?

1. A simple tr command use case is to change all lower case letters in text to upper case and vice versa, as shown below. $ cat linux.

How do you convert uppercase to UNIX?

The ^ operator converts to uppercase, while , converts to lowercase. If you double-up the operators, ie, ^^ or ,, , it applies to the whole string; otherwise, it applies only to the first letter (that isn't absolutely correct - see "Advanced Usage" below - but for most uses, it's an adequate description).


1 Answers

This will do what you are looking for:

 tr '[:upper:][:lower:]' '[:lower:][:upper:]'
like image 113
Amardeep AC9MF Avatar answered Oct 02 '22 09:10

Amardeep AC9MF