We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c4f47a0 commit aad36baCopy full SHA for aad36ba
1 file changed
implement-shell-tools/cat/cat.py
@@ -1,8 +1,12 @@
1
import argparse
2
import os
3
4
+# set argument parser
5
parser = argparse.ArgumentParser(description="Python implementation of cat command")
6
7
+# to number all lines
8
+parser.add_argument("-n", action="store_true", help="Number all lines")
9
+# To raed files
10
parser.add_argument("files", nargs="+", help="Files to read")
11
12
args = parser.parse_args()
@@ -17,4 +21,8 @@
17
21
18
22
with open(file, "r") as f:
19
23
for line in f:
20
- print(line, end ="")
24
+ if args.n:
25
+ print(f"{line_number:6}\t{line}", end="") # to print number all lines
26
+ line_number += 1
27
+ else:
28
+ print(line, end ="") # to print content of files
0 commit comments