Skip to content

Commit 0ddafe8

Browse files
committed
done cat
1 parent ace3d8e commit 0ddafe8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

implement-shell-tools/cat/cat.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
import argparse
3+
4+
parser = argparse.ArgumentParser(
5+
prog="cat",
6+
description="Concatenate and print files",
7+
)
8+
9+
parser.add_argument("-n",action='store_true', help="Number the output lines, starting at 1")
10+
parser.add_argument("-b", action='store_true', help="Number the non-blank output lines, starting at 1")
11+
parser.add_argument("path", nargs="+", help="The path to search")
12+
13+
args = parser.parse_args()
14+
for path in args.path:
15+
with open(path) as file:
16+
lines = file.readlines()
17+
line_num = 1
18+
for line in lines:
19+
lin = line.rstrip('\n')
20+
21+
if args.b:
22+
if lin =="":
23+
print()
24+
else:
25+
print(line_num, lin)
26+
line_num += 1
27+
elif args.n:
28+
print(line_num, lin)
29+
line_num += 1
30+
31+
else:
32+
print(lin)
33+

implement-shell-tools/wc/wc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import argparse
3-
import sys
43

54
parser = argparse.ArgumentParser(
65
prog="wc",

0 commit comments

Comments
 (0)