Created
January 6, 2023 07:26
-
-
Save vtta/031fc8d079d81a212ae429eb7a8bab88 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/awk -f | |
# https://unix.stackexchange.com/a/495105 | |
# usage: match_block START END MATCH [FILE] | |
# output a whole block of text enclosed by START and END that contains MATCH | |
BEGIN { | |
pstart=ARGV[1]; | |
pstop=ARGV[2]; | |
pmatch=ARGV[3]; | |
ARGV[1]=ARGV[4]; | |
ARGC=2; | |
} | |
# exp ~ /regexp/ means exp matches the regex | |
$0 ~ pstart { block = $0; output = 0; next } | |
{ block = block "\n" $0 } | |
$0 ~ pmatch { output = 1 } | |
$0 ~ pstop && output { print block; output = 0 } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment