Quantcast
Viewing latest article 1
Browse Latest Browse All 3

Answer by Sundeep for Convert markdown code block markers to criticMarkup syntax

With awk

awk '/```/{f=!f; $0 = f ? "{>>" : "<<}"} 1'
  • /```/ match three backticks anywhere in the input line. You can also use $0 == "```" to match complete line having three backticks
  • f=!f by default, uninitialized variables in awk are empty in string context and zero in numeric context. Here, you'll get f=1 the first time, f=0 next time and so on
  • $0 = f ? "{>>" : "<<}" change the input line to desired syntax based on f being true or false
  • 1 idiomatic way to print contents of $0 (the input record)

Viewing latest article 1
Browse Latest Browse All 3

Trending Articles