Skip to content

Instantly share code, notes, and snippets.

@haakonn
Created October 7, 2013 19:00
Show Gist options
  • Save haakonn/6873104 to your computer and use it in GitHub Desktop.
Save haakonn/6873104 to your computer and use it in GitHub Desktop.
Just a quick Scala script to convert a certain logfile into CSV. Instead of instinctively going to bash or python for these things, why not Scala? Just run with 'scala makecsv.scala', starts and finishes quickly. No build step or bytecode or support files, just a script.
println("date,msisdn,message")
scala.io.Source.fromFile("problem.log").getLines().foreach { line =>
val m = "^(.{19}).*msisdn='(.{10}).*msg='(.*)', status.*".r.findFirstMatchIn(line).get
println(s"""${m.group(1)},${m.group(2)},"${m.group(3)}"""")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment