How to reverse a string using unix command?

To reverse a string use the following Unix command

echo techdive | sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'

Output:

evidhcet

To reverse all the lines in a file use the following command.

cat techdive.txt | sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'

Search