如何将“program”的输出直接通过管道传输到“ex”而不将其保存为临时文件?

发布于 2024-12-19 13:36:18 字数 1467 浏览 2 评论 0原文

我有一个打印到标准输出的程序

$ ./program > log.txt
$ cat log.txt
[A]
00: efbb bf52 454d 2047 454e 5245 204f 7065
10: 7261 0d0a 5245 4d20 4441 5445 2032 3031
20: 310d 0a52 454d 2044 4953 4349 4420 3235

[B]
00: 3132 4334 3134 0d0a 5245 4d20 434f 4d4d
10: 454e 5420 2245 7861 6374 4175 6469 6f43
20: 6f70 7920 7631 2e30 6231 220d 0a50 4552

[C]
00: 464f 524d 4552 2022 5661 7269 6f75 7322
10: 0d0a 5449 544c 4520 2220 5468 6520 4f70
20: 6572 6120 4344 2031 220d 0a46 494c 4520

我想将 program 的输出通过管道传输到 xxd 以生成更多信息。

$ echo -e 'g/^00/,/^20/!xxd -r | xxd\n%p' | ex file.log
[A]
0000000: efbb bf52 454d 2047 454e 5245 204f 7065  ...REM GENRE Ope
0000010: 7261 0d0a 5245 4d20 4441 5445 2032 3031  ra..REM DATE 201
0000020: 310d 0a52 454d 2044 4953 4349 4420 3235  1..REM DISCID 25

[B]
0000000: 3132 4334 3134 0d0a 5245 4d20 434f 4d4d  12C414..REM COMM
0000010: 454e 5420 2245 7861 6374 4175 6469 6f43  ENT "ExactAudioC
0000020: 6f70 7920 7631 2e30 6231 220d 0a50 4552  opy v1.0b1"..PER

[C]
0000000: 464f 524d 4552 2022 5661 7269 6f75 7322  FORMER "Various"
0000010: 0d0a 5449 544c 4520 2220 5468 6520 4f70  ..TITLE " The Op
0000020: 6572 6120 4344 2031 220d 0a46 494c 4520  era CD 1"..FILE

问题是这样的:
如何将 program 的输出直接通过管道传输到 ex,而不将其保存为临时文件?


注意:更喜欢使用标准工具(例如,edexsedawk等)

I have a program which print to stdout.

$ ./program > log.txt
$ cat log.txt
[A]
00: efbb bf52 454d 2047 454e 5245 204f 7065
10: 7261 0d0a 5245 4d20 4441 5445 2032 3031
20: 310d 0a52 454d 2044 4953 4349 4420 3235

[B]
00: 3132 4334 3134 0d0a 5245 4d20 434f 4d4d
10: 454e 5420 2245 7861 6374 4175 6469 6f43
20: 6f70 7920 7631 2e30 6231 220d 0a50 4552

[C]
00: 464f 524d 4552 2022 5661 7269 6f75 7322
10: 0d0a 5449 544c 4520 2220 5468 6520 4f70
20: 6572 6120 4344 2031 220d 0a46 494c 4520

I want to pipe program's output to xxd to generate more information.

$ echo -e 'g/^00/,/^20/!xxd -r | xxd\n%p' | ex file.log
[A]
0000000: efbb bf52 454d 2047 454e 5245 204f 7065  ...REM GENRE Ope
0000010: 7261 0d0a 5245 4d20 4441 5445 2032 3031  ra..REM DATE 201
0000020: 310d 0a52 454d 2044 4953 4349 4420 3235  1..REM DISCID 25

[B]
0000000: 3132 4334 3134 0d0a 5245 4d20 434f 4d4d  12C414..REM COMM
0000010: 454e 5420 2245 7861 6374 4175 6469 6f43  ENT "ExactAudioC
0000020: 6f70 7920 7631 2e30 6231 220d 0a50 4552  opy v1.0b1"..PER

[C]
0000000: 464f 524d 4552 2022 5661 7269 6f75 7322  FORMER "Various"
0000010: 0d0a 5449 544c 4520 2220 5468 6520 4f70  ..TITLE " The Op
0000020: 6572 6120 4344 2031 220d 0a46 494c 4520  era CD 1"..FILE

Here is the problem:

How to pipe the output of program directly to ex without saving it as a temp file?



note: prefer to using standard tools(such as, ed, ex, sed, awk, etc.)

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

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

发布评论

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

评论(1

与酒说心事 2024-12-26 13:36:18

ex 接受“-”作为输入文件。这指示 ex 从 stdin 读取。
您可能可以执行以下操作:

./program | ex -c "your command1" -c "your command2" -

如果 -c 不能用于您的意图,那么也许您可以使用重定向来手动引入它们,因为 ex 手册页说,当 stdin 被重定向时使用 stderr 作为命令的输入。

ex accepts "-" as the input file. This indicates ex to read from stdin.
You can probably do something like:

./program | ex -c "your command1" -c "your command2" -

If -c can not be used to your intent, then maybe you can use redirection to introduce them manually as ex man page says that when stdin is redirected it uses stderr as input for commands.

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