Skip to content
Advertisement

Bash – Move last word in line to beginning of line

I need to move (in a text file) the last word on a line to the beginning of that line.

From This:

JavaScript

To This:

JavaScript

Advertisement

Answer

With GNU sed:

JavaScript

Output:

(2007) I Am Legend 
(1987) RoboCop 
(2001) Shrek 

To edit file “in place”:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement