I have a block of text that I want to put in reverse-characer order (backmasking). Is there a simple way to do that via a Unix / Cygwin command-line?


Use tac:

tac -r -s '.'


Reverse text from STDIN:
echo <YOUR TEXT GOES HERE> | tac -r -s '.'
Reverse text from a file:
tac -r -s '.' <FILENAME GOES HERE>
| improve this answer | |

Using rev is a bit simpler than tac (suggested by rmiesen). From the man page, the syntax is

rev [option] [file...]

If you omit the [file...], it'll read from stdin. So if you want to reverse text in a string, you can do

echo "some words backwards" | rev

which outputs

sdrawkcab sdrow emos

Or the alternative syntax




| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.