当文本出现在文件中时,如何用Bash做些什么 [英] How to do something with Bash when a text line appears in a file
本文介绍了当文本出现在文件中时,如何用Bash做些什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只要特定文本出现在日志文件中,我就想运行一个命令。如何在Bash中做到这一点?
I want to run a command as soon as a certain text appears in a log file. How do I do that in Bash?
推荐答案
使用命令
Use command
tail -f file.log | grep --line-buffered "my pattern" | while read line
do
echo $line
done
- 行缓冲
是这里的关键,否则读取将会失败。
The --line-buffered
is the key here, otherwise the read will fail.
这篇关于当文本出现在文件中时,如何用Bash做些什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文