Skip to content

Instantly share code, notes, and snippets.

@ayosec

ayosec/code-blocks.awk

Last active Oct 31, 2020
Embed
What would you like to do?
Extract code blocks
# Usage:
#
# $ awk -f block.awk -v START="fn myfunc" foo.rs bar.rs | pygmentize -l rs
{
if(acc == 0) {
if($0 ~ START) {
indent = match($0, /[^[:space:]]/)
acc = $0
}
} else {
acc = acc RS $0
if(match(substr($0, 0, indent), /[^[:space:]]/)) {
print acc
acc = 0
}
}
}
END {
if(acc != 0)
print acc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment