如何组合以下两个命令:
find . -print0 | grep -z pattern | tr '\0' '\n'
find . -print0 | grep -z pattern | xargs -0 my_command
进入单个管道?如果我不需要 NUL 分隔符那么我可以这样做:
find . | grep pattern | tee /dev/tty | xargs my_command
我想避免使用这样的临时文件:
find . -print0 | grep -z pattern > tempfile
cat tempfile | tr '\0' '\n'
cat tempfile | xargs -0 my_command
rm tempfile
这个问题是这些答案的后续问题:
1)使用/dev/tty显示中间管道结果:
https://unix.stackexchange.com/a/178754/8207082 https://unix.stackexchange.com/a/178754/8207082
2) 使用 NUL 分隔的文件列表:
https://stackoverflow.com/a/143172/8207082 https://stackoverflow.com/a/143172/8207082
编辑使用my_command
代替command
.
后续问题:
在子 shell 内写入 /dev/tty 的 Makefile 规则? https://stackoverflow.com/questions/44731163/
您只需将 tee 更改为指向 proc sub,然后在其中执行完全相同的操作即可。
find . -print0 | grep -z pattern | tee >(tr '\0' '\n' > /dev/tty) | xargs -0 command
以这种方式使用 tee 的唯一问题是,如果 xargs 命令也打印到屏幕上,则所有输出可能会变得混乱,因为管道和进程子都是异步的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)