Conditional Batch File Editing

Adopted Mmark for Math Posts


During the adoption of Mmark for math posts on this blog, I had to insert markup: mmark at the last line of front matter of the source file of each math post.

Seek help

I separated this into two SO questions

  1. Sed conditional match and execute command with offset, and
  2. A question about AWK multiple line recognition.


From #1., I learnt the use of variables in AWK scripts. From #2, some users explained how these variables can be used for multi-line regex search.

Here’s the actual command ran.

find content/post/**/*.md -print0 |
while IFS= read -d '' -r file; do
awk '
/^- math$/ {
  if(lastLine == "categories:") {
{ lastLine = $0 }
/^---$/ && f { print "markup: mmark"; f=0 }
' $file > ${file%.*}.bak
awk  sed  Mmark 

No comment

Your email address will not be published. Required fields are marked *.