Welcome to the ccwc
tool! This project is a Go implementation of the classic Unix wc
(word count) command-line tool, designed to work on Windows, macOS, and Linux. Like its sibling wc
, ccwc
is used to count bytes, characters, words, and lines in files or from standard input.
The ccwc-tool
was developed as a modern, cross-platform alternative with several key motivations driving its design:
-
Cross-platform Compatibility:
Designed to work seamlessly on Windows, macOS, and Linux. Go's portability ensures the tool runs efficiently on any platform without dependency issues, making it ideal for developers and system administrators who work across diverse environments.
-
Lightweight and Efficient:
Written in Go,
ccwc-tool
takes advantage of Go’s lightweight, statically compiled binaries and high performance. It operates quickly with minimal system overhead, making it suitable for high-performance environments where resource efficiency is crucial. -
Enhanced Usability:
While maintaining the core functionalities of
wc
,ccwc-tool
introduces additional input methods (like reading from standard input) and provides more intuitive flag handling, offering a simple yet powerful utility for analyzing text files on various operating systems. -
Extendibility:
Its simple and modular design makes
ccwc-tool
easy to extend and contribute to. Developers can add new features or improve performance, ensuring the tool evolves with the community's needs.
- Count Bytes (-c): Use the
c
flag to get the total number of bytes in a file. - Count Lines (-l): The
l
flag provides the number of lines in the file. - Count Words (-w): Use the
w
flag to count the number of words in the file. - Count Characters (-m): The
m
flag counts characters in the file, supporting multibyte characters. - Default Mode: When no flags are provided, the tool will display the byte, word, and line counts for the file.
- Support for Standard Input: The tool can also read from standard input if no file is provided, making it useful in pipelines.
-
Clone the repository:
git clone https://github.com/rafaelmgr12/cwcc-tool.git cd ccwc-tool
-
Build the tool using Go:
go build -o ccwc
-
You can now run the
ccwc
tool on your system.
ccwc
provides the following options:
-
Count the number of bytes in a file:
./ccwc -c filename.txt
-
Count the number of lines in a file:
./ccwc -l filename.txt
-
Count the number of words in a file:
./ccwc -w filename.txt
-
Count the number of characters in a file:
./ccwc -m filename.txt
-
Default: Get the line, word, and byte count without any flags:
./ccwc filename.txt
-
Read from standard input:
cat filename.txt | ./ccwc -l
Here’s how you can use ccwc
with a sample text file:
-
File
test.txt
:Go is an open-source programming language that makes it easy to build simple, reliable, and efficient software.
-
Running
ccwc
ontest.txt
:./ccwc -w test.txt
Output:
12 test.txt
This shows that
test.txt
contains 12 words.
To make ccwc
available as a command-line tool that you can run from any directory (similar to wc
), follow these steps to add it to your system's PATH
:
-
After building
ccwc
, move the binary to a directory that's in your system'sPATH
(for example,/usr/local/bin
):sudo mv ./ccwc /usr/local/bin/ccwc
-
Verify that the tool is now accessible from anywhere:
ccwc -h
If you see the help output for
ccwc
, you've successfully set it up!
-
After building
ccwc
, move the binary to a directory that is included in your system'sPATH
. For example, you can place it inC:\Program Files\
:Move-Item .\ccwc.exe 'C:\Program Files\ccwc.exe'
-
Add the directory to the system
PATH
:- Open the Start Menu, search for "Environment Variables," and select "Edit the system environment variables."
- In the "System Properties" window, click "Environment Variables."
- Under "System Variables," find the
Path
variable, select it, and click "Edit." - Click "New" and add the path to where you moved
ccwc.exe
(e.g.,C:\Program Files\
). - Click "OK" to close all windows.
-
Verify that
ccwc
is now accessible from the command prompt:ccwc -h
If you see the help output for
ccwc
, you've successfully set it up!
Contributions are welcome! If you would like to contribute, feel free to fork the repository, make your changes, and open a pull request. Please ensure that your changes are well-documented and that you write tests for any new functionality.
-
Fork this repository
-
Create your feature branch:
git checkout -b feature/YourFeatureName
-
Commit your changes:
git commit -m "Add feature description"
-
Push to the branch:
git push origin feature/YourFeatureName
-
Open a pull request
This project is licensed under the MIT License. See the LICENSE file for more details.