我想使用egrep从文件执行多字符串搜索,但是使用变量来存储搜索字符串值。这将帮助我以编程方式更改搜索字符串。例如: -
SEARCHSTRING='typesetting industry|printer took|specimen'
cat /tmp/input.file|egrep $SEARCHSTRING > /tmp/output.file
input.file内容:
*Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book. It has survived not only five centuries,
but also the leap into electronic*
output.file内容(预期):
*Lorem Ipsum is simply dummy text of the printing and typesetting industry.
1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book. It has survived not only five centuries,*
请帮忙
答案 0 :(得分:2)
双引号变量,也使用grep -E
而不是egrep
egrep "$SEARCHSTRING" inputfile
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book. It has survived not only five centuries,