Skip to content

Commit 5ce2651

Browse files
committed
-b flag
1 parent 0a8c55d commit 5ce2651

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • implement-shell-tools/cat

implement-shell-tools/cat/cat.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
parser = argparse.ArgumentParser(prog="cat", description="Prints the output of a file to the console")
44
parser.add_argument("-n", "--number", help="Displays the lines along with their number", action="store_true")
5+
parser.add_argument("-b", "--nonblank", help="Displays the lines along with their number", action="store_true")
56
parser.add_argument("path", help="The file path", nargs="+")
67

78
args = parser.parse_args()
89

910
show_lines = args.number
11+
non_blank = args.nonblank
1012

1113
text = ""
1214
i = 1
@@ -18,10 +20,16 @@
1820
text_list = text.split("\n")
1921
text_list.pop(len(text_list) - 1)
2022

21-
if (show_lines == False):
23+
if (show_lines == False and non_blank == False):
2224
print("\n".join(text_list))
2325
exit()
2426

2527
for line in text_list:
26-
print(" " + str(i) + " " + line)
27-
i += 1
28+
if non_blank == True and line != "":
29+
print(" " + str(i) + " " + line)
30+
i += 1
31+
elif non_blank == False:
32+
print(" " + str(i) + " " + line)
33+
i += 1
34+
else:
35+
print("")

0 commit comments

Comments
 (0)