Last active
October 31, 2020 07:34
-
-
Save ayosec/ca540da92f5020915f5f50f183a31d70 to your computer and use it in GitHub Desktop.
Extract 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
# 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