Thank you very much bhargav and zazzybob! Both are excellent ideas. I wish I were Admin right now so that I could get the GNU grep installed (cheers to you, mate!
), but because that is not an option, I started with your code, bhargav (which was on target indeed!). Here I present my somewhat more robust resultant script (which I call fin):
if [ $# -ne 2 ]
then
echo "\n Syntax is: fin string #lines \n"
exit 1
fi
# search multiple files for string $1
# and print specified #lines $2 before and after
for filename in *.c*
do
a=`grep -n "$1" $filename | cut -d":" -f 1`
if [ $a ]
then
f=$2
((b=a+f))
((c=a-f))
echo "\n \n \n $filename: \n"
sed -n ""$c","$b" p " $filename
fi
done