-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
In combination with listToMD5(), I wrote a Groovy utils function to remove specific lines from a file and return an ArrayList:
// Function to filter certain lines from a file and return an ArrayList
// Remember that the index starts at 0 in Groovy
public static ArrayList excludeLines(String inFilePath, linesToExclude) {
def inputLines = new File(inFilePath).readLines()
if (linesToExclude.size() >= 0){
Set<Integer> setOfLines = (0..inputLines.size()-1) as Set
def newSetOfLines = setOfLines.minus(linesToExclude)
return inputLines.getAt(newSetOfLines)
}
else {
return inputLines
}
}Test usage:
{ assert listToMD5(UTILS.excludeLines("$outputDir/foo.txt", [1,3,7,8,9,11,12,13,14,15,20,21])) == listToMD5(UTILS.excludeLines("some/other/local.txt", [1,3,7,8,9,11,12,13,14,15,20,21])) },
# or to compare
{ assert snapshot(
listToMD5(UTILS.excludeLines("$outputDir/foo.txt", [1,3,7,8,9,11,12,13,14,15,20,21]))
).match() }The Groovy code could probably be improved, still, it might be useful this as an nft-utils function.
maxulysse
Metadata
Metadata
Assignees
Labels
No labels