在journalctl内部grep中,是否可以指定选项仅输出匹配的模式?

在journalctl内部grep中,是否可以指定选项仅输出匹配的模式?

我有以下日记消息:

$ journalctl _COMM=kwin_wayland -o cat --since "-10s"
...
kwin_screencast: Dropping a screencast frame because the compositor is slow
kwin_screencast: Dropping a screencast frame because the compositor is slow
js: hello
goodbue
kwin_screencast: Dropping a screencast frame because the compositor is slow
kwin_screencast: Dropping a screencast frame because the compositor is slow
...

我只想提取以“js:”开头的消息。

来自journalctl手册:

-g, --grep=
过滤输出到 MESSAGE= 字段与指定正则表达式匹配的条目。使用与 PERL 兼容的正则表达式,有关语法的详细说明,请参阅 pcre2pattern(3)。

普通 grep 可以使用 -P 选项在 PCRE 模式下工作。正如所描述的这里,我可以用来-o仅匹配模式,并\K在模式本身中删除开头。所以这个命令:

$ journalctl _COMM=kwin_wayland -o cat --since "-10s" | grep -Po "js: \K.*"
hello

给了我几乎我想要的东西(不幸的是,它也切断了下一行消息)。

我想使用单个命令,即不通过管道传输到普通 grep,而是使用-gjournalctl 选项。

我可以为内部 grep 指定这样的模式:

$ journalctl _COMM=kwin_wayland -o cat --since "-10s" -g "js: \K.*" 
js: hello
goodbue

它会打印我的消息(幸运的是,还有下一行消息)。但它与“js:”部分有关。我想把它扔掉。

是否可以以某种方式指定journalctl的内部grep选项“-o”?
或者,我可以在模式中使用分组,但同样,如何指定我只想输出该组?

相关内容