gpt4 book ai didi

bash - egrep AND 运算符

转载 作者:行者123 更新时间:2023-11-29 09:02:54 25 4
gpt4 key购买 nike

<分区>

我知道 egrep 有一个非常有用的方法,可以通过使用将两个表达式组合在一起:

egrep "pattern1.*pattern2"|egrep "pattern2.*pattern1" filename.txt|wc -l

然而,在搜索三个表达式时,有一种简单的方法可以使用 egrep 的 AND 运算符,因为随着您添加额外的表达式,排列呈指数增长。

我知道使用 sort|uniq -d 的另一种方法,但我正在寻找更简单的解决方案。

编辑:

我目前的搜索方式总共会产生五个结果:

#!/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

mumps@debianMumpsISR:~/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

同时:

mumps@debianMumpsISR:~/Medline2012$ grep "angio" rtrans.txt|grep "cardio" rtrans.txt|grep "pulmonary" rtrans.txt|wc -l
185

产生 185 行文本,因为它只获取肺部搜索的值,而不是所有三个搜索的值。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com