下面的命令没有给出任何结果。我想grep
从文件中提取错误行并插入到表中。
不起作用的命令:
tail -f logfile.log | grep ERROR|while read msg; do psql -d testdb -c insert into t values('$msg'); done
Run Code Online (Sandbox Code Playgroud)
但是如果我grep ERROR
从命令中删除代码,它会按预期工作。我不确定发生了什么?
运行正常的命令:
tail -f logfile.log|while read msg; do psql -d testdb -c insert into t values('$msg'); done
Run Code Online (Sandbox Code Playgroud)
您可以假设文件中有以下数据:
ERROR
sql committed
ERROR
ERROR
error
...
Run Code Online (Sandbox Code Playgroud)