首页 > 解决方案 > 具有可变原因文件且数据为空的 Grep

问题描述

当我在脚本中使用此命令时:

grep -A 12 -B 37 "1000221411" /home/ashb/20181007/soap_nohup_20181007_0*.log | awk '{$1=""}1' > abcdef.txt

但是当我尝试放置变量以在日志文件中查找更多 id 时:

grep -A 12 -B 37 ${b} /home/ashb/20181007/soap_nohup_20181007_0*.log | awk '{$1=""}1' > abcdef.txt

然后 abcdef.txt 原来是空文件。我试着echo ${b}去做,它在我的路上。我该如何解决?的输入${b}

1000221411
1000248725
1000287875
1000296552

标签: bashshellgrep

解决方案


看起来这就是你想要做的:

$ cat file
foo
1000221411
bar
1000296552

$ echo "$b"
1000221411
1000248725
1000287875
1000296552

$ grep -f <(echo "$b") file
1000221411
1000296552

推荐阅读