ccwc
is a command-line utility written in Go for analyzing text files. It calculates the number of bytes, lines, words, and
characters in a file or from standard input. Inspired by Unix tools like wc
, it provides flexible options for text analysis.
Features
- Count bytes, lines, words, or characters in a file.
- Supports input via file paths or piped input.
- Simple and intuitive flags for specific operations. Installation
- Clone the repository:
git clone https://github.com/rajatsing/ccwc.git
cd ccwc
- Build the binary:
go build -o ccwc
- (Optional) Add it to your
PATH
for global use:
mv ccwc /usr/local/bin/
Usage
- Count bytes:
ccwc -c filename.txt
- Count lines:
ccwc -l filename.txt
- Count words:
ccwc -w filename.txt
- Count characters:
ccwc -m filename.txt
- Count lines in piped input:
cat filename.txt | ccwc -l
- Count words in piped input:
echo "This is a test" | ccwc -w
If no flags are specified, the default output includes all metrics:
ccwc filename.txt
Example output:
342190 7145 5200
(Output format: bytes lines words
)
Flags
Flag | Shorthand | Description |
---|---|---|
--bytes |
-c |
Number of bytes in the file |
--lines |
-l |
Number of lines in the file |
--words |
-w |
Number of words in the file |
--chars |
-m |
Number of characters in the file |
Examples |
- Count lines in a file:
ccwc -l sample.txt
- Count words from a piped input:
echo "Hello world!" | ccwc -w