2016-11-30 1 views
1

Ich möchte mehr-String-Suche aus einer Datei mit egrep durchführen, aber Variable verwenden, um die Such-String-Werte zu speichern. Das wird mir helfen, die Suchzeichenfolgen programmgesteuert zu ändern. Beispiel: -So verwenden Sie VARILE als Suchzeichenfolge in egrep

SEARCHSTRING='typesetting industry|printer took|specimen' 
cat /tmp/input.file|egrep $SEARCHSTRING > /tmp/output.file 

input.file Inhalt:

*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 Inhalt (erwartet):

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

Bitte helfen

Antwort

2

doppelte Anführungszeichen die Variable, auch verwenden grep -E über 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, 
Verwandte Themen