2016-11-30 11 views
1

egrepを使用してファイルから複数の文字列を検索したいが、変数を使用して検索文字列の値を格納したい。これは、プログラムで検索文字列を変更するのに役立ちます。例: -egrepでvaribleを検索文字列として使用する方法

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,* 

答えて

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, 
関連する問題