Skip to content

Instantly share code, notes, and snippets.

@unakatsuo
Created July 14, 2014 16:51
Show Gist options
  • Save unakatsuo/3ec609b731ee0f2a0812 to your computer and use it in GitHub Desktop.
Save unakatsuo/3ec609b731ee0f2a0812 to your computer and use it in GitHub Desktop.
AWK example to print contents in **```shell** code blocks
#!/bin/sh
awk 'BEGIN{blkline=0; skip=0; }
$0 ~ /^## EXAMPLE:$/ && blkline == 1 { skip=1; }
$0 ~ /^```$/ && blkline > 0 {blkline=0;}
blkline > 0 && skip == 0 {print $0; blkline++; }
$0 ~ /^```shell$/ && blkline == 0 {blkline=1; skip=0;}
' <<'EXAMPLE_MD'
## Title
paragraph
-----
paragraph
```
Skipped to print.
```
```shell
Skipped.
```
Skip marker out of code block should not affect with the awk skip flag.
## EXAMPLE:
```shell
which awk ls yes
echo "RUN"
```
```shell
## EXAMPLE:
Also skipped to show here.
```
```shell
echo "RUN"
## EXAMPLE:
Skip marker is ignored.
```
EXAMPLE_MD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment