grep replacement
bob desinger
bd at hpsemc.HP.COM
Sun Jun 12 16:28:46 AEST 1988
> 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 <phrase`
if test $1 -ne 28 -o $2 -ne 62 -o $3 -ne 355
then echo ! phrase should have 28 lines, 62 words, and 355 characters
echo ! but has $1 lines, $2 words, and $3 characters
fi
chmod 775 phrase
echo "End of shell archive."
exit 0
More information about the Comp.unix.wizards
mailing list