我知道的egrep有安定的一個非常有用的方法兩個表達式一起使用:egrep的AND運算
egrep "pattern1.*pattern2"|egrep "pattern2.*pattern1" filename.txt|wc -l
不過是有搜索三個表達式時作爲排列成倍增加使用egrep的年代和操作的簡便方法因爲你添加額外的表達式。
我知道另一種方式去使用sort|uniq -d
但是我正在尋找一個更簡單的解決方案。
編輯:
我目前的搜索方式將產生總計5個結果:
#!/bin/bash
pid=$$
grep -i "angio" rtrans.txt|sort|uniq|egrep -o "^[0-9]+ [0-9]+ " > /tmp/$pid.1.tmp
grep -i "cardio" rtrans.txt|sort|uniq|egrep -o "^[0-9]+ [0-9]+ " > /tmp/$pid.2.tmp
grep -i "pulmonary" rtrans.txt|sort|uniq|egrep -o "^[0-9]+ [0-9]+ " > /tmp/$pid.3.tmp
cat /tmp/$pid.1.tmp /tmp/$pid.2.tmp|sort|uniq -d > /tmp/$pid.4.tmp
cat /tmp/$pid.4.tmp /tmp/$pid.3.tmp|sort|uniq -d > /tmp/$pid.5.tmp
egrep -o "^[0-9]+ [0-9]+ " /tmp/$pid.5.tmp|getDoc.mps > /tmp/$pid.6.tmp
head -10 /tmp/$pid.6.tmp
[email protected]:~/Medline2012$ AngioAndCardioAndPulmonary.script
1514 Structural composition of central pulmonary arteries. Growth potential after surgical shunts.
1517 Patterns of pulmonary arterial anatomy and blood supply in complex congenital heart disease
with pulmonary atresia
3034 Controlled reperfusion following regional ischemia.
3481 Anaesthetic management for oophorectomy in pulmonary lymphangiomyomatosis.
3547 A comparison of methods for limiting myocardial infarct expansion during acute reperfusion--
primary role of unload
雖然:
[email protected]:~/Medline2012$ grep "angio" rtrans.txt|grep "cardio" rtrans.txt|grep "pulmonary" rtrans.txt|wc -l
185
產生185行的文本,因爲它只是採取的值在肺部搜索而不是全部三個搜索。
什麼是一個'sort'有一個'grep'辦?我真的沒有得到這個。 – Rubens 2013-03-02 17:28:55
你的例子應該讀'egrep「pattern1。* pattern2 | pattern2。* pattern1」文件名。txt' – 2013-03-02 18:07:55