麻烦管道通过的sed [英] Trouble with piping through sed
问题描述
我有麻烦的管道通过sed的。一旦我的管道输出到SED,我不能管其他的sed,输出
I am having trouble piping through sed. Once I have piped output to sed, I cannot pipe the output of sed elsewhere.
wget -r -nv http://127.0.0.1:3000/test.html
输出:
2010-03-12 04:41:48 URL:http://127.0.0.1:3000/test.html [99/99] -> "127.0.0.1:3000/test.html" [1]
2010-03-12 04:41:48 URL:http://127.0.0.1:3000/robots.txt [83/83] -> "127.0.0.1:3000/robots.txt" [1]
2010-03-12 04:41:48 URL:http://127.0.0.1:3000/shop [22818/22818] -> "127.0.0.1:3000/shop.29" [1]
我管通过sed的输出来获得URL的清洁列表:
I pipe the output through sed to get a clean list of URLs:
wget -r -nv http://127.0.0.1:3000/test.html 2>&1 | grep --line-buffered -v ERROR | sed 's/^.*URL:\([^ ]*\).*/\1/g'
输出:
http://127.0.0.1:3000/test.html
http://127.0.0.1:3000/robots.txt
http://127.0.0.1:3000/shop
我想那么转储输出到文件,所以我这样做:
I would like to then dump the output to file, so I do this:
wget -r -nv http://127.0.0.1:3000/test.html 2>&1 | grep --line-buffered -v ERROR | sed 's/^.*URL:\([^ ]*\).*/\1/g' > /tmp/DUMP_FILE
我打断这个过程几秒钟后,并检查文件,但它是空的。
I interrupt the process after a few seconds and check the file, yet it is empty.
有趣,下面的产率没有输出(与上述相同,但通过猫管道SED输出):
Interesting, the following yields no output (same as above, but piping sed output through cat):
wget -r -nv http://127.0.0.1:3000/test.html 2>&1 | grep --line-buffered -v ERROR | sed 's/^.*URL:\([^ ]*\).*/\1/g' | cat
我为什么不能管的sed像猫另一个程序的输出?
Why can I not pipe the output of sed to another program like cat?
推荐答案
在sed的正在写另一个进程或文件,就会缓存数据。
When sed is writing to another process or to a file, it will buffer data.
尝试添加 - 无缓冲
选项的sed
Try adding the --unbuffered
options to sed.
这篇关于麻烦管道通过的sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!