Search code examples
regexlinuxbashawksed

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:

com.e.h/float

I want to get output as:

float/h.e.com 

I have tried the command:

rev file.txt

but I have got all the reverse output: taolf/h.e.moc 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


Solution

  • 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 "([/.])"' f