AnalogueLife

Analogue witterings...

More shell scripting today.

In the Markdown template there is a section called frontmatter. This is an area in the document that holds values that can be used in the final output ie. author, date etc.

One of the value sets is tags. I wanted to be able to get these as individual values and inject them into the final standalone page. The two commands that can do this are awk and sed. I am using a combination of the two.

awk first finds and cuts the values, places them in a temporary file then sed copies those values and enters them in the html page.

          awk '/tags:/{for(i=2; i<=NF; i++) print "<li>" $i "</li>"}' <$file >tmpl/tags.txt
        
          sed -i "/<!-- TAGS -->/r tmpl/tags.txt" "${file%.md}.html"
        

At some point I want to connect the tags up as a searchable item.

  • awk
  • sed
  • bash
  • linux
© matthew@analoguelife | 2023-12-31 17:17