仅通过过滤器输送 STDERR [英] Pipe only STDERR through a filter

查看:24
本文介绍了仅通过过滤器输送 STDERR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 bash 中,有没有什么办法可以在将 STDERR 与 STDOUT 统一之前通过过滤器通过管道传输它?也就是说,我想要

标准输出────────────────┐├──────>终端/文件/任何STDERR ── [过滤器] ──┘

而不是

标准输出────┐├────[过滤器]────>终端/文件/任何STDERR ────┘

解决方案

这里有一个例子,模仿了 如何在 bash 中交换文件描述符.a.out 的输出如下,没有STDXXX:"前缀.

STDERR:标准错误输出标准输出:更规律./a.out 3>&1 1>&2 2>&3 3>&- |sed 's/e/E/g'更规律标准错误输出

引自上述链接:

<块引用>

  1. 首先将标准输出保存为 &3(&1 被复制到 3)
  2. 接下来将标准输出发送到标准错误(&2 被欺骗成 1)
  3. 将 stderr 发送到 &3 (stdout)(&3 被欺骗到 2)
  4. close &3(&- 被欺骗成 3)

Is there any way, in bash, to pipe STDERR through a filter before unifying it with STDOUT? That is, I want

STDOUT ────────────────┐
                       ├─────> terminal/file/whatever
STDERR ── [ filter ] ──┘

rather than

STDOUT ────┐
           ├────[ filter ]───> terminal/file/whatever
STDERR ────┘

解决方案

Here's an example, modeled after how to swap file descriptors in bash . The output of a.out is the following, without the 'STDXXX: ' prefix.

STDERR: stderr output
STDOUT: more regular

./a.out 3>&1 1>&2 2>&3 3>&- | sed 's/e/E/g'
more regular
stdErr output

Quoting from the above link:

  1. First save stdout as &3 (&1 is duped into 3)
  2. Next send stdout to stderr (&2 is duped into 1)
  3. Send stderr to &3 (stdout) (&3 is duped into 2)
  4. close &3 (&- is duped into 3)

这篇关于仅通过过滤器输送 STDERR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆