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 1+ import argparse
2+ parser = argparse .ArgumentParser (
3+ prog = "count-containing-words" ,
4+ description = "Counts words in a file that contain a particular character" ,
5+ )
6+
7+ counterNumber = 1
8+ parser .add_argument ("-n" , action = "store_true" , help = "number all lines" )
9+ parser .add_argument ("-b" , action = "store_true" , help = "The character to search for" )
10+ parser .add_argument ("path" , nargs = "+" , help = "The file to search" )
11+
12+ args = parser .parse_args ()
13+
14+ for file_path in args .path :
15+ with open (file_path , "r" ) as f :
16+ content = f .read ()
17+ arrText = content .split ("\n " )
18+
19+ if args .b :
20+ for i in range (len (arrText )):
21+ if arrText [i ].strip () != "" :
22+ print (counterNumber ,arrText [i ])
23+ counterNumber += 1
24+
25+ elif args .n :
26+ for i in range (len (arrText )):
27+ print (counterNumber , arrText [i ])
28+ counterNumber += 1
29+ else :
30+ print (content )
You can’t perform that action at this time.
0 commit comments