Skip to content

Instantly share code, notes, and snippets.

@ayosec
Last active October 31, 2020 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayosec/ca540da92f5020915f5f50f183a31d70 to your computer and use it in GitHub Desktop.
Save ayosec/ca540da92f5020915f5f50f183a31d70 to your computer and use it in GitHub Desktop.
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