Shell查看文件的最后5行,并对每行进行正则匹配,代码如下:
#!/bin/sh pattern="HeartBeat" tail -n 5 /home/test/log/log_20150205.log | while read line do if [[ $line =~ $pattern ]] then echo "Match" else echo "No match" fi echo $line done
时间: 2024-10-13 14:22:34
Shell查看文件的最后5行,并对每行进行正则匹配,代码如下:
#!/bin/sh pattern="HeartBeat" tail -n 5 /home/test/log/log_20150205.log | while read line do if [[ $line =~ $pattern ]] then echo "Match" else echo "No match" fi echo $line done