My Scala Sed project: More features, returning strings
By Alvin Alexander. Last updated: July 11 2019
Table of Contents
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
- A
Map
of 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 topBasic use
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: