Skip to content

Instantly share code, notes, and snippets.

@kirichkov
Created September 2, 2012 15:59
Show Gist options
  • Save kirichkov/3600875 to your computer and use it in GitHub Desktop.
Save kirichkov/3600875 to your computer and use it in GitHub Desktop.
Reverse a text file's lines - the first line becoming the last
cat -n FILE | sort -nr | cut -c 8- > NEWFILE
@kirichkov
Copy link
Author

Reverses FILE's content, making the last line to become the first. Each line's content is not modified, just the line's position.
Tweek the cut -c X to get proper results on different OSs.
This script is tested on MacOS X and with files with less than 100 lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment