Path: utzoo!attcan!uunet!husc6!mailrus!ames!pasteur!ucbvax!decwrl!hplabs!hpda!hpsemc!bd From: bd@hpsemc.HP.COM (bob desinger) Newsgroups: comp.unix.wizards Subject: Re: grep replacement Message-ID: <570013@hpsemc.HP.COM> Date: 12 Jun 88 06:28:46 GMT References: <15030@brl-adm.ARPA> Organization: HP Technology Access Center, Cupertino, CA Lines: 66 > Along this same general line it would be nice to be abble to > look for paterns that span lines. Here's a script called `phrase' from Dougherty and O'Reilly's _Unix_Text_Processing_ book. It finds patterns that are possibly split across lines. Its usage is: phrase "phrase to find" files ... It doesn't have all those grep options, but at least it gets you halfway there. -- bd #! /bin/sh # This is a shell archive. Remove anything before this line, # then unwrap it by saving it in a file and typing "sh file". # # Wrapped by bd at hpsemc on Sat Jun 11 23:26:46 1988 # Contents: # phrase PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:$PATH; export PATH echo 'At the end, you should see the message "End of shell archive."' echo Extracting phrase cat >phrase <<'@//E*O*F phrase//' : find phrases, perhaps split across lines # From _Unix_Text_Processing_ by Dougherty & O'Reilly, p. 378 if [ $# -lt 2 ] then echo "Usage: `basename $0`" '"phrase to find" file ...' exit 1 else search="$1" # pattern shift fi for file do sed ' /'"$search"'/b N h s/.*\n// /'"$search"'/b g s/ *\n/ / /'"$search"'/{ g b } g D' $file done @//E*O*F phrase// set `wc -lwc