I wonder if it is legit to have a awk file call a function or process lines
directly using
function print_dk_sections(line)
{
if (line ~ /^### DK/) {
printing = 1
empty_count = 0
return 0
}
if (printing) {
print line
if (line ~ /^$/) {
empty_count++
if (empty_count == 2) { printing = 0 }
}
}
return 1
}
{
## Preferred default mode due to better modularity and
## maintainability using a dedicated function to process lines.
if (mode == "fn") {
print_dk_sections($0)
}
## ------------------------------------------------------------
## Idiomatic and efficient but less modular than using a function.
## Uses pattern-action blocks directly inside the condition.
else if (mode == "direct-pa") {
/^### DK/ {
printing=1;
empty_count=0;
next; # Skip printing this line
}
printing {
print
if ($0 ~ /^$/) {
empty_count++
if (empty_count == 2) { printing = 0 }
}
}
}