同时管道grep并重定向到stdout

Ama*_*man 5 redirect grep stdout

在Linux bash中,我正在尝试运行命令和grep以获取参数:

command | grep
Run Code Online (Sandbox Code Playgroud)

但是,我需要将commad的结果重定向到stdout并同时将其传递给grep(我需要在stdout中看到grep结果和命令结果).

我google了一下,尝试了一些变化,例如:

command | tee /dev/tty | grep
Run Code Online (Sandbox Code Playgroud)

但是,没有运气.

我不想用......

command
command | grep
Run Code Online (Sandbox Code Playgroud)

因为它很难看:)

谢谢,

oog*_*oga 5

尝试

command | tee >(grep whatever)
Run Code Online (Sandbox Code Playgroud)

请注意,这两个符号之间没有空格:>(.

  • 谢谢,这解决了我原来的问题,但添加了额外的问题这是我的代码: snmpget -v2c -c public 10.241.32.42 .1.3.6.1.4.1.28589.2.5.96.0 | tee >(grep -E "字符串: \"[0-9]\.[0-9]{3}\"") ;; SNMPv2-SMI::enterprises.28589.2.5.96.0 = "" ;; 回声 $?;; 0;; }}} 无论 grep 成功与否,“command | tee >(grep)”的退出状态都是“0”。 (2认同)