Usando o "awk":
#!/bin/sh
awk '
function print_section() {
# Only print section if "1234" was encountered
if (valid == 1) print section;
}
{
if (/something/) {
# Start new section
section = $0;
}
else if (/^\s*$/) {
# Empty line -> output previous section
if (section ne "") {
print_section();
section = "";
valid = 0;
}
}
else if (section ne "") {
# Add line to section if one has been started
section = section "\n" $0;
if (/1234/) valid = 1;
}
}
END {
# End of file, print current section if it exists
print_section();
}
' file