input
> a='Vikas'
> echo $a
Vikas
my required output is
echo $a | <some command>
vIKAS
input
> a='Vikas'
> echo $a
Vikas
my required output is
echo $a | <some command>
vIKAS
$ echo Vikas | LC_ALL=C tr a-zA-Z A-Za-z
vIKAS
The utility tr
translates characters; it takes two arguments representing sets of characters; it then copies standard input to standard output replacing each character found in the first set with the corresponding character in the second set. In this application, it replaces lowercase letters with uppercase letters and vice-versa. See the manual page of tr(1) for details and for other processing which tr
can perform.
echo Vikas | tr [a-z][A-Z] [A-Z][a-z]
vIKAS
can you please say why LC_ALL=C is required ?
– Vikas Venna Nov 22 '17 at 13:03C
, the meaning of a-z
and A-Z
is unknown, since these ranges are locale dependent (for example, in some locales this will also include non-ASCII characters). Setting it to C
guarantees that these ranges mean what most people expect.
– Chris Down
Nov 22 '17 at 13:06
A-Z
as representing all characters which sort between A
and Z
in the current locale. Your tr
may do this or not, I don't know. By setting LC_ALL=C
I am certain that A-Z
means ABCDEFGHIJKLMNOPQRSTUVWXYZ
.
– AlexP
Nov 22 '17 at 13:11
you can use tr command with [:upper:] and [:lower:] options, like this:
echo "aBcDeF" |tr '[:upper:][:lower:]' '[:lower:][:upper:]'
AbCdEf
also you can use sed command (stands for 'Stream editor'), like this:
echo "abcd ABCD" |sed 'y/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/'
sed has more flexibility, it means you can define any character mapping. for example you can convert numbers to hackers letter with this command:
echo "52065218802365" |sed 'y/0123456789/OIZEhSGLBP/'
SZOGSZIBBOZEGS
tr
command.. – Sundeep Nov 22 '17 at 12:51