Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse input order with sed

I have a file, lets call it 'a.txt' and this file contains the following text line

do to what

I'm wondering what the SED command is to reverse the order of this text to make it look like

what to do

Do I have to do some sort of append? Like append 'do' to 'to' so it would look like

to ++ do (used ++ just to make it clear)

like image 351
user1634254 Avatar asked Oct 28 '12 11:10

user1634254


1 Answers

I know tac can do something related

$ cat file
 do to what
$ tac -s' ' file

what to do  $

Where the -s defines the separator, which is by default a newline.

like image 198
Bernhard Avatar answered Nov 15 '22 10:11

Bernhard