hare krshn
hare krshn

Reputation: 386

groovy script read file line by line and print

I have a file and data is as shown below, can any one please help with sharing groovy scripting, read the lines and print 1st and 3rd column ? Without ParseCSV will be appeciated.

b8e9363a2bcfc03e3bbe6fa4045570967a227cbb    refs/heads/meta/cibuild/acme  repo1
457f2d592547925c4f7d790ce4d44588140e938f    refs/heads/meta/releasebuild/acme repo1
9376be234bb0ac2716861ff235009f78fa3efdf6    refs/heads/acme repo1
121b707a4a74d29ae208ecbfd009fab396eaaffa    refs/meta/releasebuild/acme repo1

Upvotes: 0

Views: 532

Answers (1)

daggett
daggett

Reputation: 28564

http://docs.groovy-lang.org/latest/html/groovy-jdk/java/io/File.html#splitEachLine(java.lang.String,%20groovy.lang.Closure)

new File("path/to/file").splitEachLine(/\s+/){row->
    println "col1=${row[0]} col3=${row[2]}"
}

Upvotes: 3

Related Questions