Shell遍历文件,对每行进行正则匹配

时间:2024-04-01 11:07:21

Shell查看文件的最后5行,并对每行进行正则匹配,代码如下:

#!/bin/sh

pattern="HeartBeat"
tail -n /home/test/log/log_20150205.log | while read line
do
if [[ $line =~ $pattern ]]
then
echo "Match"
else
echo "No match"
fi
echo $line
done