Skip to content

Commit df5b8e5

Browse files
Implement wc command with -l, -w, and -c flags
1 parent 5d1476b commit df5b8e5

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
description="Count lines, words, and characters"
77
)
88
parser.add_argument("paths", nargs='+', help="Files to count")
9+
parser.add_argument("-l", "--lines", action="store_true", help="Count lines only")
10+
parser.add_argument("-w", "--words", action="store_true", help="Count words only")
11+
parser.add_argument("-c", "--chars", action="store_true", help="Count characters only")
912

1013
args = parser.parse_args()
1114

@@ -19,4 +22,11 @@
1922
words = len(content.split())
2023
chars = len(content)
2124

22-
print(f"{lines:8}{words:8}{chars:8} {path}")
25+
if args.lines:
26+
print(f"{lines:8} {path}")
27+
elif args.words:
28+
print(f"{words:8} {path}")
29+
elif args.chars:
30+
print(f"{chars:8} {path}")
31+
else:
32+
print(f"{lines:8}{words:8}{chars:8} {path}")

0 commit comments

Comments
 (0)