ccwc is a simple command line tool written in Zig, which takes inspiration from the Unix wc command. This tool can read a specified file or standard input and output the number of bytes, lines, words, or characters, based on the supplied options.
These instructions will help you get a copy of the project up and running on your local machine.
Zig Programming Language (version 0.10.1 or newer)
To build the ccwc command line tool, navigate to the project directory and run:
zig build-exe source/main.zig
This command compiles the source code and produces an executable named main.
The ccwc tool can be used with the following options:
- -c: Count the number of bytes.
- -l: Count the number of lines.
- -w: Count the number of words.
- -m: Count the number of characters. If no option is provided, the tool will default to counting bytes, lines, and words.
To count the number of bytes in text.txt:
./main -c text.txt
To count the number of lines:
./main -l text.txt
For counting words:
./main -w text.txt
To count characters:
./main -m text.txt
Additionally, ccwc can read from standard input (stdin), allowing it to be used in a pipeline. For example, to count lines from text.txt using cat:
cat text.txt | ./main -l
In this case, if no filename is provided, ccwc reads the input from stdin.