sed help to convert from lowercase to uppercase and vice versa!

Hello,
can sed be used to convert all letters of a file from uppercase to lowercase and vice versa?i know tr command can be used but with sed is it possible?
i came up with this :-

sed 'y/[A-Z]/[a-z]/' file1

actually the above command is also not working! Please help me. Thanks in advance :slight_smile:

cat file | sed y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/

thanks amitranjansahu :slight_smile:
but why can't i use character class??
also the solution that you gave will transform from lower to upper case what if i want to reverse the case? i mean the letters that are lower should get convert to upper and those which are upper should get converted to lower?how can i do that?

sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/

amitranjansahu :slight_smile:
you are very funny !!
i meant i want to reverse the case i want both of them to happen at the same time

suppose file contents are

Laala TIWAri

then the output should be
lAALA tiwaRI

can you tell me how to write regular expression to achieve this?

The below may meet your requirements(Upper to lower and vice versa at the same time)

$ echo "Laala TIWAri" |sed 'y/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/'
lAALA tiwaRI

But a more simple code in sed would be more interesting...

thanks Whiteboard :slight_smile:
yeah you are right! a more simple code (if any exists) would be more interesting because it requires writing 26 *4 characters
anyways thanks a lot Whiteboard.