This project is a command-line utility written in Go that counts the number of words or lines from standard input. This is similar to the wc
command in Unix-like systems, providing functionality to count words by default and lines with an optional flag.
- Word Counting: Counts the total number of words by default.
- Line Counting: With the
-l
flag, counts the total number of lines instead of words.
Ensure that Go (version 1.23.2 or later) is installed on your system.
-
Clone this repository:
git clone https://github.com/abrishk26/wc.git cd wc
-
Build the project:
go build -o wc
Run the compiled program and pipe in text via standard input. Use the -l
flag to count lines instead of words.
-
Counting Words:
echo "Hello World" | ./wc
-
Counting Lines:
echo -e "Line 1\nLine 2" | ./wc -l
main.go
: Contains the main functionality, including:- Parsing flags for word or line counting.
- Counting words or lines using the
count
function, which scans input and increments a counter based on the mode specified.