Skip to content

Instantly share code, notes, and snippets.

@counter2015
Created May 17, 2019 06:52
Show Gist options
  • Save counter2015/ec9f9de7dbe1a14f2023bd160c31d1c7 to your computer and use it in GitHub Desktop.
Save counter2015/ec9f9de7dbe1a14f2023bd160c31d1c7 to your computer and use it in GitHub Desktop.
a simple implement of grep
val filesHere = (new java.io.File(args(0))).listFiles
def fileLines(file: java.io.File) =
scala.io.Source.fromFile(file).getLines().toList
def grep(pattern: String) =
for (
file <- filesHere
if file.getName.endsWith(".scala");
line <- fileLines(file)
if line.trim.matches(pattern)
) println(file + ": " + line.trim)
grep(args(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment