Jaffer Wilson Jaffer Wilson - 1 year ago 67
Linux Question

How to reverse all the words in a file with bash in Ubuntu?

I would like to reverse the complete text from the file.

Say if the file contains:


I want to get output as:


I have tried the command:

rev file.txt

but I have got all the reverse output:

Is there a way I can get the desired output. Do let me know. Thank you.

Here is teh link of teh sample file: Sample Text

Answer Source

Is it possible to use Perl?

perl -nlE 'say reverse(split("([/.])",$_))'  f

This one-liner reverses all the lines of f, according to PO's criteria.

If prefer a less parentesis version:

perl -nlE 'say reverse split "([/.])"' ex 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download