I need to move (in a text file) the last word on a line to the beginning of that line.
From This:
JavaScript
x
I Am Legend (2007)
RoboCop (1987)
Shrek (2001)
To This:
JavaScript
(2007) I Am Legend
(1987) RoboCop
(2001) Shrek
Advertisement
Answer
With GNU sed:
JavaScript
sed 's/(.*)((.*))/2 1/' file
Output:
(2007) I Am Legend (1987) RoboCop (2001) Shrek
To edit file “in place”:
JavaScript
sed -i 's/(.*)((.*))/2 1/' file