Reputation: 23
Suppose, I have a file (file.txt) that contain few numbers with characters.
1 2 3 4 (23)
23 2 1 (51)
2 1 4 (11)
And, I would like to read it in reverse order as given below.
(23) 4 3 2 1
(51) 1 2 23
(11) 4 1 2
I tried:
awk '{print $NF,$0}' file.txt | sort -nr
Is there a command-line in Linux or a mini-code (in AWK or in C++ or some other language) to perform this task?
Upvotes: 0
Views: 97
Reputation: 88583
awk '{for (i=NF;i>0;i--){printf $i" "};printf "\n"}' file.txt
Output:
(23) 4 3 2 1 (51) 1 2 23 (11) 4 1 2
Upvotes: 4