-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathcat.py
More file actions
29 lines (22 loc) · 713 Bytes
/
cat.py
File metadata and controls
29 lines (22 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("files", nargs="+")
parser.add_argument("-n", action="store_true")
parser.add_argument("-b", action="store_true")
args = parser.parse_args()
line_number = 1
for file in args.files:
try:
f = open(file, "r")
for line in f:
if args.b and line.strip() != "":
print(f" {line_number}", line, end="")
line_number += 1
elif args.n and not args.b:
print(f" {line_number}", line, end="")
line_number += 1
else:
print(line, end="")
f.close()
except:
print("cat:", file, "not found")