Quantcast
Viewing all articles
Browse latest Browse all 26

Answer by Mark Booth for How can I reverse the order of lines in a file?

If you want to modify the file in place, you can run

sed -i '1!G;h;$!d' filename

This removes the need to create a temporary file and then delete or rename the original and has the same result. For example:

$tac file > file2$sed -i '1!G;h;$!d' file$diff file file2$

Based on the answer by ephemient, which did almost, but not quite, what I wanted.


Viewing all articles
Browse latest Browse all 26

Trending Articles