Sed:匹配后打印所有行 [英] Sed : print all lines after match
问题描述
我在使用sed
后得到了我的研究结果:
I got my research result after using sed
:
zcat file* | sed -e 's/.*text=\(.*\)status=[^/]*/\1/' | cut -f 1 - | grep "pattern"
但它只显示我切割的部分.如何在匹配后打印所有行?
But it only shows the part that I cut. How can I print all lines after a match ?
我使用的是 zcat,所以我不能使用 awk.
I'm using zcat so I cannot use awk.
谢谢.
已
这是我的日志文件:
[01/09/2015 00:00:47] INFO=54646486432154646 from=steve idfrom=55516654455457 to=jone idto=5552045646464 guid=100021623456461451463 n
um=6 text=hi my number is 0 811 22 1/12 status=new survstatus=new
我的目标是找到所有使用电话号码向我的网站发送垃圾邮件的用户(使用 grep "pattern"
),然后打印所有行以获取有关每个垃圾邮件的所有信息.问题是 INFO 或 id 中可能存在匹配项,因此我使用 sed
来先获取文本.
My aim is to find all users that spam my site with their telephone numbers (using grep "pattern"
) then print all the lines to get all the information about each spam. The problem is there may be matches in INFO or id, so I use sed
to get the text first.
推荐答案
也许这就是您真正想要的?查找匹配pattern"的行并提取 text=
之后的字段,直到 status=
?
Maybe this is what you actually want? Find lines matching "pattern" and extract the field after text=
up through just before status=
?
zcat file* | sed -e '/pattern/s/.*text=\(.*\)status=[^/]*/\1/'
你没有透露 pattern
实际上是什么——如果它是一个变量,你不能在它周围使用单引号.
You are not revealing what pattern
actually is -- if it's a variable, you cannot use single quotes around it.
注意 \(.*\)status=[^/]*
将通过 survstatus=new
在您的示例中匹配.那可能不是您想要的?似乎任何地方都没有 status=
后跟斜杠——你真的应该更详细地解释你真正想要完成的事情.
Notice that \(.*\)status=[^/]*
would match up through survstatus=new
in your example. That is probably not what you want? There doesn't seem to be a status=
followed by a slash anywhere -- you really should explain in more detail what you are actually trying to accomplish.
您的问题标题是匹配后的所有行",所以也许您想要text=
之后的所有内容?那么就是
Your question title says "all line after a match" so perhaps you want everything after text=
? Then that's simply
sed 's/.*text=//'
即将 text=
替换为空,保留其余部分.(我相信你可以弄清楚如何将周围的脚本更改为 zcat file* | sed '/pattern/s/.*text=//'
... 哎呀,也许我的信任失败了.)
i.e. replace up through text=
with nothing, and keep the rest. (I trust you can figure out how to change the surrounding script into zcat file* | sed '/pattern/s/.*text=//'
... oops, maybe my trust failed.)
这篇关于Sed:匹配后打印所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!