Filter lines
The filterLine returns those lines where the closure returns true.
The file test.txt contains the following contents.
Hello World 1234 Hello World 1234
def file = new File("test.txt") StringWriter writer = new StringWriter() file.filterLine(writer) { line -> line.contains("Hello World") } println writer.toString()
This groovy snippets will output the following.
Hello World Hello World 1234