#!/bin/bash
number=$1;
msg=$1;
file=$2;
if [ $1 ]; then
msg=$1;
else
echo "msg is empty";
exit 1;
fi;
if [ $2 ]; then
file=$2;
else
echo "filename is empty";
exit 2;
fi;
if [ $3 ]; then
last=$3;
else
last=5;
fi;
if [ $4 ]; then
length=$4;
else
length=10;
fi;
echo $number,$file;
let "number=$number+5";
echo $number;
list=`cat -n $file | grep -i $msg | cut -f1`
for iter in $list
do
echo $iter;
number=$iter;
let "number=$number+$last";
head -n $number $file | tail -n $length
done;
# head -n $number $file | tail -n 10
网友评论