#!/bin/csh -f

# Works like
#   grep pattern file
# but instead of giving you the whole line in which the match occurred,
# it just gives you the actual match to the pattern.
# One line may generate multiple lines in the output as it may contain
# multiple matches to the pattern, but only disjoint matches are reported.

set pat = "$1"

foreach file ($argv[2-])
sed -n 's/\('"$pat"'\)/toss\\
keep\1keep\\
toss/gp' $file | \
     sed -n 's/^keep\(.*\)keep$/\1/p'
end
