Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import sys
- def _help():
- res = """Usage:
- more [options] <file>...
- A file perusal filter for CRT viewing.
- Options:
- -s squeeze multiple blank lines into one
- +<number> display file beginning from line number
- -V display version information and exit
- """
- return res
- def more(options, fname):
- exit_options = {
- '-V': lambda: 'more from util-linux 2.27'
- }
- for option in options:
- if option in exit_options:
- return exit_options[option]()
- output_options = {
- '-s': lambda s: '\n'.join([line for line in s.split('\n') if line])
- }
- with open(fname, 'r') as f:
- res = f.read()
- for option in options:
- if option in output_options:
- res = output_options[option](res)
- lines = res.split('\n')
- for i in range(0, len(lines), 30):
- print('\n'.join(lines[i:i + 30]))
- input('')
- return None
- if __name__ == '__main__':
- res = None
- if len(sys.argv) < 2:
- res = _help()
- else:
- options = []
- for token in sys.argv[1:]:
- if token.startswith('-'):
- options = options + [token]
- fname = sys.argv[-1]
- res = more(options, fname)
- if res:
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement