This is a Go implementation to mimic the Unix's wc utility that dislays the number of lines, words and bytes contained in an input file - with a few changes.
- In context of this tool, counting lines means counting the number of new line characters in the input file.
- A word is defined as a string of characters delimited by characters which are not alphabets or digits.
-
Clone the repo and put the input text files in the root folder.
-
Following is the Synopsis for the tool, that you'll run on your terminal:
gowc [-options] [file ...]
- Following are the options that can be used as flags:
-c Count the number of bytes in the input file
-l Count the number of new line characters in the input file
-w Count the number of words in the input file
The default values of these flags is false
.
You can also use the -help
flag to see these help messages on your terminal.
- Here is an example to get the number of words in the input text file:
% go run ./gowc.go -w file.txt
-
When using multiple flags together, the order of output will be: lines, words, bytes and file name.
-
If more than one input file is specified, a line for each file is printed showing the results.