#!/bin/sh # mgrep: matches patterns across multiple lines. # usage: mgrep pattern [file] PATH=/bin:/usr/bin:/usr/local/bin export PATH # Check the argument list. case "$#" in 0) echo 'usage: mgrep pattern [file]'; exit 1 ;; *) ;; esac # Search for the pattern. sed -e "N h s/ *\n/ / /$1/{ g p d } g D" $2 exit 0