Created
December 31, 2019 17:41
-
-
Save mtholder/be325166940f374d2af65e6ccc09b71d to your computer and use it in GitHub Desktop.
simple script to reverse the first n-1 lines of a file with n lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| '''Reverses the order of the first n-1 lines of a file | |
| and writes it to stdout. | |
| ''' | |
| import sys | |
| fp = sys.argv[1] | |
| with open(fp, 'r', encoding='utf-8') as inp: | |
| lines = inp.readlines() | |
| last = lines.pop(-1) | |
| lines.reverse() | |
| lines.append(last) | |
| for line in lines: | |
| sys.stdout.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment