wcgo
is a custom command-line tool inspired by the Unix wc
command written in go as per Coding challenges
by John Cricket
. It can be used to count lines, words, bytes, and characters from a given file or standard input.
- Count lines, words, bytes, and characters.
- Supports file input or standard input (stdin).
- Provides easy-to-use command-line flags to specify the desired count.
To build the wcgo
CLI tool, clone the repository and build the binary:
# Clone the repository
$ git clone <repository_url>
# Navigate to the project directory
$ cd wc-go
# Build the binary
$ go build -o wcgo
After running the above command, you will have an executable file named wcgo
.
The wcgo
tool provides several command-line options to specify what counts you want:
-l
: Count the number of lines.-w
: Count the number of words.-c
: Count the number of bytes.-m
: Count the number of characters.
You can use multiple flags at once to get different counts simultaneously.
If you have a file named example.txt
and you want to use wcgo
to count lines, words, or other metrics:
# Count lines, words, and bytes in the file
$ ./bin/wcgo -l -w -c example.txt
You can also use wcgo
to read input directly from stdin
. For example:
# Pipe text into wcgo to count lines, words, and bytes
$ echo "Hello World! This is a test." | ./bin/wcgo
-l
: Print the number of lines.-w
: Print the number of words.-c
: Print the number of bytes.-m
: Print the number of characters.
If no flags are provided, wcgo
defaults to counting lines, words, and bytes.
For a file named example.txt
:
$ ./bin/wcgo -f example.txt
10 45 256 example.txt
This output shows:
- 10 lines
- 45 words
- 256 bytes
- The filename (
example.txt
)
You can also run the tests by running test command in go
$ go test
If you need to compile wcgo
for another platform, you can use Go's cross-compilation capabilities:
-
For Linux:
GOOS=linux GOARCH=amd64 go build -o wcgo
-
For Windows:
GOOS=windows GOARCH=amd64 go build -o wcgo.exe
-
For macOS:
GOOS=darwin GOARCH=amd64 go build -o wcgo
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome! Feel free to open an issue or submit a pull request for any improvements or new features.