Chinaunix
标题:
shell中匹配字符串功能
[打印本页]
作者:
risepp
时间:
2008-05-21 17:57
标题:
shell中匹配字符串功能
我现在如果有多行的内容需要进行查找,比如
ABC
123
456
我想查看某个文件中的内容,是否含有这三行,不是分别含有就可以了,比如ABC,或者123都不算
必须同时有这三行,grep能查询的出来么?
谢谢!
作者:
super_ebo
时间:
2008-05-21 18:05
noticing...
作者:
小鹭
时间:
2008-05-21 18:27
~/shell> cat 3.txt
33
ABC
123
456
333
~/shell> paste -s 3.txt | sed -n l |grep 'ABC\\t123\\t456'
33\tABC\t123\t456\t333$
----------------------------------------
~/shell> cat 4.txt
33
ABC
xxx
123
456
333
~/shell> paste -s 4.txt | sed -n l |grep 'ABC\\t123\\t456'
~/shell>
作者:
seeLnd
时间:
2008-05-21 18:37
awk 'BEGIN{RS="ABC\n123\n456"} RT!=""{print FILENAME}' file1 file2 file3
复制代码
作者:
寂寞烈火
时间:
2008-05-21 18:40
awk '/ABC/{n=NR;a=$0}/123/{m=NR;b=$0}/456/{o=NR;c=$0}END{if(o==(n+2)&&m==(n+1))printf "%s\n%s\n%s\n" ,a,b,c;else print "error"}'
作者:
springwind426
时间:
2008-05-21 18:50
如果行可以不连续的话
grep -q "ABC" file && grep -q "123" file && grep -q "456" file && echo OK
复制代码
作者:
risepp
时间:
2008-07-08 10:14
非常感谢,学习中~~~~
作者:
blackold
时间:
2008-07-08 10:24
标题:
回复 #6 springwind426 的帖子
Good Job!!
作者:
MYSQLER
时间:
2008-07-08 11:58
强贴啊。。学习一下
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2