Created
July 14, 2014 16:51
-
-
Save unakatsuo/3ec609b731ee0f2a0812 to your computer and use it in GitHub Desktop.
AWK example to print contents in **```shell** code blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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