这个算编程吗?
#!/bin/bash
# Author: Amorphou
# Oct 2010
# grepfwd $pattern $infile $linenumber1 $linenumber2 $outfile
# for each occurence of a pattern, grep forward by $linenumbers
# Without a 5th arg, save to files fwdgrep.$int by default
# defaults
((linenumber1=0))
((linenumber2=0))
FILES="fwdgrep"
SED=/bin/sed
if [ "$#" -lt "2" -o "$#" -gt "5" ]
then
echo "USAGE: $0 pattern infile linenumber1 linenumber2 [optional]outfile"
exit 0
fi
if [ "$#" -ge "3" ]
then
if echo "$3" | grep "^[0-9]*$">tmp0
then
((linenumber1="$3"))
((linenumber2="$3"))
else
echo "arg3 not a number"
rm tmp0
exit 0
fi
rm tmp0
if [ "$#" -ge "4" ]
then
if echo "$4" | grep "^[0-9]*$">tmp0
then
((linenumber2="$4"))
if [ "$4" -lt "$3" ]
then
echo "error: startline > endline"
exit 0
fi
else
echo "arg4 not a number"
rm tmp0
exit 0
fi
if [ "$#" -eq "5" ]
then
FILES="$5"
fi
# endif [ "$#" -ge "4" ] #
fi
# endif [ "$#" -ge "3" ]#
fi
if [ -e tmp0 ]
then
rm tmp0
fi
cmdfile="seds"
linenumbers=`$SED -n /"$1"/= $PWD"/$2"`
j=$((1))
echo "#/bin/bash" > $cmdfile
for i in $linenumbers
do
startline=$(($i+$linenumber1))
endline=$(($i+$linenumber2))
echo "$SED -n '$startline,$endline p' "$2" > $FILES.$j" >> $cmdfile
((j+=1))
done
if [ "$j" -gt "1" ]
then
chmod u+x $cmdfile
$PWD/$cmdfile
rm $PWD/$cmdfile
else
echo "grepfwd $1 $2 ..."
echo "No match found"
fi