Sea*_*mus 9 shell utilities text-processing
我有一个程序texcount
可以输出 LaTeX 文档中的字数。我还可以将它的输出通过管道传输sed
到 TeX 换行符并将其写入一个文件,然后我可以将其包含在我的最终文档中。但是当我执行texcount foo.tex | sed s/$/'\\\\'/ > wc.tex
命令行输出时texcount
被抑制。
如何获取要在终端中显示并通过管道传输到 sed的第一个命令的输出?
您可以对第二个命令使用匿名管道:
texcount foo.tex | tee >(sed s/$/'\\\\'/ > wc.tex)
Run Code Online (Sandbox Code Playgroud)
您需要“tee”命令,它允许您拆分管道。
texcount foo.tex | tee >output.txt | sed s/$/'\\\\'/ > wc.tex ; cat output.txt
Run Code Online (Sandbox Code Playgroud)
这将为您留下额外的 output.txt 文件。阅读更多信息:http : //www.unixtutorial.org/2007/12/tee-replicate-standard-output/ 你也可以做“man tee”。
小智 6
你可以使用相当惯用的
texcount foo.tex | tee /dev/tty | sed s/$/'\\\\'/ > wc.tex
Run Code Online (Sandbox Code Playgroud)
/dev/tty
是指当前进程的控制终端的魔法装置。