read line reverse from a file [duplicate]

2019-09-14 09:53发布

问题:

This question already has an answer here:

  • How to reverse a list of words in a shell string? 13 answers

how do I read line reverse from a file like,

#cat file
hello world 
hello world bash

so I need output like this,

world hello 
bash world hello 

回答1:

awk '{for(i=NF;i>=1;i--) if(i!=1)printf $i" ";else print $i}'
world hello
bash world hello


标签: linux bash