File tree Expand file tree Collapse file tree
implement-shell-tools/cat Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33args = sys .argv [1 :]
44
5- show_numbers = False
5+ option = "none"
66paths = []
77
8- # separate flags and paths
8+ # parse args
99for arg in args :
1010 if arg == "-n" :
11- show_numbers = True
11+ option = "n"
12+ elif arg == "-b" :
13+ option = "b"
1214 else :
1315 paths .append (arg )
1416
1517for path in paths :
1618 with open (path , "r" ) as file :
1719 lines = file .readlines ()
1820
19- if show_numbers :
20- i = 1
21- for line in lines :
22- print (f"{ i } { line .rstrip ()} " )
23- i += 1
24- else :
25- print ("" .join (lines ))
21+ line_number = 1
22+
23+ for line in lines :
24+
25+ line = line .rstrip ("\n " )
26+
27+ if option == "n" :
28+ print (f"{ line_number } { line } " )
29+ line_number += 1
30+
31+ elif option == "b" :
32+ if line != "" :
33+ print (f"{ line_number } { line } " )
34+ line_number += 1
35+ else :
36+ print ("" )
37+
38+ else :
39+ print (line )
You can’t perform that action at this time.
0 commit comments