Created
May 17, 2019 06:52
-
-
Save counter2015/ec9f9de7dbe1a14f2023bd160c31d1c7 to your computer and use it in GitHub Desktop.
a simple implement of grep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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