bash - 具有可变原因文件且数据为空的 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
解决方案
看起来这就是你想要做的:
$ cat file
foo
1000221411
bar
1000296552
$ echo "$b"
1000221411
1000248725
1000287875
1000296552
$ grep -f <(echo "$b") file
1000221411
1000296552
推荐阅读
- python - Python 正则表达式从字符串中间删除特殊字符并忽略其他任何内容
- python - 如何将链表的最后一个元素移动到python中的第一个元素(下面的代码)?
- javascript - Divs被切断了?
- c++ - 混合 Rcpp 模块和 Rcpp::export
- java - TabLayout 迁移到 AndroidX
- python - 如何在python中的zip文件夹中创建文件?
- c++ - 如何在 Cython 中链接嵌套的 C++ 库
- javascript - 使用 laravel 中的 db 数据更改 tui-calender 中的数据
- reactjs - ReactJS D3 - 如何放大 D3 地理世界地图
- python - 如何在python中水平堆叠两个矩阵