Skip to content

Instantly share code, notes, and snippets.

@fizz
Last active September 30, 2016 01:40
Show Gist options
  • Save fizz/5827438 to your computer and use it in GitHub Desktop.
Save fizz/5827438 to your computer and use it in GitHub Desktop.
It's like grep for blocks (useful for git spelunking)
# 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