比赛后SED打印N线

发布于 2025-02-02 01:54:53 字数 613 浏览 3 评论 0原文

我有一个包含以下行的文件:

some junk
in here

log number 1
line1, data, here
line2,data,here
line3,data,here
and so on

some other
junk

log number 2
line one, some,data
line two, some,data
line three, blablabla

我想在 n-th-th 匹配日志编号...行之后匹配和打印大约一百行。 此解决方案有效,但我不想在我的sed命令中键入100 ns。

另外/log。*\ n(。*\ n){2}/gm(匹配后打印2行)在 Regex101 ,但在我的终端上不匹配\ n)。

我使用Arch Linux和GNU SED 4.8版。

I have a file containing these lines:

some junk
in here

log number 1
line1, data, here
line2,data,here
line3,data,here
and so on

some other
junk

log number 2
line one, some,data
line two, some,data
line three, blablabla

I want to match and print about hundred lines after n-th match of log number ... lines.
this solution works, but I don't want to type a 100 Ns in my sed command.

Also /log.*\n(.*\n){2}/gm (printing 2 lines after match) works on regex101 but not on my terminal (sed doesn't match \n).

I use arch linux and GNU sed version 4.8.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗琴音 2025-02-09 01:54:53

这样的事情不起作用吗?

$ sed -n '/log.*1/,+4p' file
log number 1
line1, data, here
line2,data,here
line3,data,here
and so on

如果您只需要在比赛结束后打印100行,则应该全部需要。

$ sed -n '/log.*1/,+100p' file

Does something like this not work?

$ sed -n '/log.*1/,+4p' file
log number 1
line1, data, here
line2,data,here
line3,data,here
and so on

If you just need to print 100 lines after the match, it should be all you need.

$ sed -n '/log.*1/,+100p' file
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文