My Scala Sed project is still a work in progress, but I made some progress on a new version this week. My initial need this week was to have Sed return a
String rather than printing directly to STDOUT. This change gave me more ability to post-process a file. After that I realized it would really be useful if the custom function I pass to Sed had two more pieces of information available to it:
- The line number of the string Sed passed to it
Mapof key/value pairs the helper function could use while processing the file
Note: In this article “Sed” refers to my project, and “sed” refers to the Unix command-line utility.Back to top
In a “basic use” scenario, this is how I use the new version of Sed in a Scala shell script to change the “layout:” lines in 55 Markdown files whose names are in the files-to-process.txt file:
Scala FAQ: How can I use regular expression (regex) pattern matching in a
match expression (a Scala match/case expression)?
As I wrote in my Scala sed class post earlier today, Jon Pretty’s Kaleidoscope project lets you use string pattern-matching code in Scala
match expressions. This enables regex pattern-matching code like this:
A few times during the past year I got tired of trying to remember the Unix/Linux
sed syntax while wanting to make edits to many files, so this weekend I wrote a little
sed-like Scala class.
Kaleidoscope is a Scala pattern-matching library created in a string interpolator style.