/ Published in: Groovy
Read the first (or some number) of lines of file to treat special (e.g. the first line is column headings), then use eachLine to read in rest of file. Also illustrate simple use of GZIPInputStream. Other experiments had me convinced that eachLine always reset to beginning of stream, but apparently not.
Expand |
Embed | Plain Text
#!/usr/bin/env groovy import java.util.zip.*; fileName = args[0] // Create a GZIPInputStream... // And a reader so we get the nice readLine... // Read the special first line...column headings say. firstLine = reader.readLine() println "firstLine: $firstLine" // Read the rest of the file...reader picks up where // it was left off with eachLine println "line: $line" }
Comments
Subscribe to comments
You need to login to post a comment.

If you aren't dealing with gzipped files, you could also use the withReader syntax, which is a bit less verbose. Something like: