Searching lines before & After in Unix
#! /usr/bin/sh
#-----------------------------------------------
#Program used to search a seed in a program
#-----------------------------------------------
SEED=$1
LINE=$2
FILE1=$3
for X in `awk '/'"$SEED"'/{ print NR }' $FILE1 `
do
echo ----------------------- $SEED --------------------------------------
NOB=`expr $X - $LINE`
NOA=`expr $X + $LINE`
if [ $NOB -lt 1 ]; then NOB=1
fi
for J in `awk 'NR == '"$NOB"',NR == '"$NOA"' { if(NF!=0) print; else print "\n" }' $FILE1 `
do
echo $J
done
echo -------------------------------------------------------------------
done
#-----------------------------------------------
#Program used to search a seed in a program
#-----------------------------------------------
SEED=$1
LINE=$2
FILE1=$3
for X in `awk '/'"$SEED"'/{ print NR }' $FILE1 `
do
echo ----------------------- $SEED --------------------------------------
NOB=`expr $X - $LINE`
NOA=`expr $X + $LINE`
if [ $NOB -lt 1 ]; then NOB=1
fi
for J in `awk 'NR == '"$NOB"',NR == '"$NOA"' { if(NF!=0) print; else print "\n" }' $FILE1 `
do
echo $J
done
echo -------------------------------------------------------------------
done

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home