Skip to content

Commit dad3daa

Browse files
committed
implementing flag -n
1 parent 29258e9 commit dad3daa

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

  • implement-shell-tools/cat

implement-shell-tools/cat/cat.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88
parser.add_argument("-b",action="store_true",help="number the output lines without blank ones")
99
parser.add_argument("path",nargs="*",help="files to read")
1010
args=parser.parse_args()
11-
print(args)
11+
# print(args)
12+
line_number=1
1213
for per_file in args.path :
1314
with open(per_file,"r") as f:
14-
print(f.read())
15+
if args.n :
16+
lines=f.readlines()
17+
for line in lines :
18+
print(line_number,line,end="")
19+
line_number=line_number+1
20+
21+
22+
print(f.read())
1523

0 commit comments

Comments
 (0)