Last active
September 30, 2016 01:40
-
-
Save fizz/5827438 to your computer and use it in GitHub Desktop.
It's like grep for blocks (useful for git spelunking)
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
# Example: git show <treeish> | awk -f block.awk | |
# Selectively print sections matching regex in body of matches(), below | |
function matches(block) { | |
return (block ~ /\-\?\>/) | |
} | |
/diff/{ | |
# start of a new block, process the previous | |
if (prevblock"" && matches(prevblock)) print prevblock | |
prevblock = sep = "" | |
} | |
{ | |
prevblock = prevblock sep $0 | |
sep = RS | |
} | |
END { | |
if (prevblock"" && matches(prevblock)) print prevblock | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment