2010-07-09 19:02:04 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
2015-03-11 19:54:28 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2010-07-09 19:02:04 +00:00
|
|
|
import sys
|
|
|
|
from getopt import getopt
|
|
|
|
|
|
|
|
usage = '''
|
|
|
|
python cat.py -o OUTFILE FILE1 FILE2 .... FILEn
|
|
|
|
|
|
|
|
Replacement for:
|
|
|
|
cat FILE1 FILE2 ... .FILEn > OUTFILE
|
|
|
|
If the -o argument is not given, writes to stdout.
|
|
|
|
'''
|
|
|
|
|
|
|
|
outfile = ""
|
|
|
|
|
|
|
|
(options, args) = getopt(sys.argv[1:], "ho:")
|
|
|
|
for (opt, param) in options:
|
|
|
|
if opt == "-o":
|
|
|
|
outfile = param
|
|
|
|
elif opt == "-h":
|
2015-03-11 19:54:28 +00:00
|
|
|
print(usage)
|
2010-07-09 19:02:04 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
out = sys.stdout
|
|
|
|
if outfile:
|
|
|
|
out = open(outfile, "w")
|
|
|
|
|
|
|
|
for f in args:
|
|
|
|
fil = open(f, "r")
|
|
|
|
for l in fil:
|
|
|
|
out.write(l)
|
|
|
|
fil.close()
|
|
|
|
|
|
|
|
if outfile:
|
|
|
|
out.close()
|