This project is a Unix/Lunix wc
written in go from Coding Challenge. It processes text files to provide various statistics, including the number of bytes, lines, words, and characters.
- Byte count (
-c
): Outputs the number of bytes in the file. - Line count (
-l
): Outputs the number of lines in the file. - Word count (
-w
): Outputs the number of words in the file. - Character count (
-m
): Outputs the number of characters in the file.
- Prerequisites: Ensure you have Go installed. If not, download and install it from the official Go website.
- Clone the repository:
git clone https://github.com/Jonath-z/unix-wc-tool
- Navigate to the project directory:
cd unix-wc-tool
You can test with various flags to get the desired file statistics. Below are some examples:
- Get the number of bytes in a file:
go run main.go -c test.txt
- Get the number of lines in a file:
go run main.go -l test.txt
- Get the number of words in a file:
go run main.go -w test.txt
- Get the number of characters in a file:
go run main.go -m test.txt
The code is organized into several functions to handle different tasks:
contains(s []string, str string) bool
: Checks if a string is present in a slice of strings.getByteNumber(fileName string) int64
: Returns the size of the file in bytes.getNumberOfLines(fileName string) int
: Returns the number of lines in the file.countWords(fileName string) int
: Returns the number of words in the file.counterCharacter(fileName string) int
: Returns the number of characters in the file.ProcessFile(fileName string, cb func(string))
: Processes the file by checking its existence and executing a callback function.main()
: Parses command-line flags and invokes appropriate functions based on the flags provided.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.