Skip to content

matt4biz/go-class-counts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Run on Repl.it

Go class: line counts example

The first example counts all words in a file (equivalent to wc -w).

$ go run ./counts rich2.txt
2558 total words

$ wc -w rich2.txt
    2558 rich2.txt

The second counts only unique words.

$ go run ./uniq rich2.txt
1197 unique words

This can be checked by using AWK to find the words and then running them through a pipeline of other Unix commands:

$ awk '{for (i=1; i<=NF; i++) {print $i}}' rich2.txt|sort|uniq|wc -l
    1197

The file rich2.txt is taken from Shakespeare, Richard II act 2 scene 1.

About

Go class: Word count example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages