我在通過sed管道時遇到問題。一旦我有管道輸出到sed,我不能在其他地方輸出sed。通過sed管道故障
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的清潔列表輸出:
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
我想然後將輸出轉儲到文件,所以我這樣做:
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
我在幾秒鐘後中斷了進程並檢查了該文件,但它是空的。
有趣的是,下面的產率沒有輸出(與上面相同,但管道SED輸出通過貓):
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將像貓另一個程序的輸出?
sed應該可以正常使用管道,例如:echo「foo」| sed's/foo/bar/g'>/tmp/foo對我來說工作得很好。向sed添加-u選項是否有所作爲?或者嘗試在檢查文件之前讓該過程完成。 sed可能只是做了太多的內部緩衝結果。 – bdk 2010-03-11 17:58:16