LoginSignup
1
1

More than 5 years have passed since last update.

ヒットしたキーワードの前後数行をファイルに抽出

Posted at

set

export UE=3 #上何行
export SITA=4 #下何行

export FILE=hoge #ファイル名

export KEY=keyword #キーワード

exec

for i in grep -n $KEY $FILE|awk -F: '{print $1 } '
do
export BASE=expr $i + $SITA

export SITAA=`expr $UE + 1 + $SITA`

echo ----------
head -$BASE $FILE| tail -$SITAA
echo ----------

done

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1