Created
July 27, 2014 15:08
-
-
Save dmahapatro/8700b8e81e7c5c3dafa2 to your computer and use it in GitHub Desktop.
Gr8GroovyWorkshop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def myString = """ | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, | |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum | |
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
""" | |
def myStringAsList = myString.split() | |
// Word Count | |
println "Word Count -> ${myStringAsList.size()}" | |
// Number of times each word is used | |
def timesUsed = myStringAsList.groupBy().collectEntries { k, v -> [ k, v.size() ] } | |
println "# of times each word is used -> \n$timesUsed" | |
//Character Count | |
println "Character count -> ${myString.size()}" | |
// Words in File | |
new File('/Users/dmahapatro/projects/gr8conf/test.txt').withReader { | |
def wordsInFile = it.readLine().split().groupBy().collectEntries { k, v -> [ k, v.size() ] } | |
println "# of times words used eachline in file \n$wordsInFile" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment