https://unix.stackexchange.com/questions/82944/how-to-grep-for-text-in-a-file-and-display-the-paragraph-that-has-the-text There is probably a similarly easy way to do it with awk, but in perl: cat file | perl -ne 'BEGIN { $/="\n\n" }; print if $_ =~ /42B/;' That basically says to split the file into chunks delimited by blank lines, then to only print those chunks that match your regular expression.