sed -e'$!d'无法正常工作?


10

当我跑步时:

sudo /usr/local/nginx/sbin/nginx -t

我回来了:

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

我只想要最后一行,所以我运行:

sudo /usr/local/nginx/sbin/nginx -t | sed -e '$!d'

但是我和没有sed的感觉一样。

Answers:


13

您的命令可能输出到stderr而不是stdout。要将stderr重定向到stdout:

sudo /usr/local/nginx/sbin/nginx -t 2>&1 | sed -e '$!d'

如果只希望输出的最后一行,也可以使用tail -n 1代替sed


是的,就是这样
Philip Kirkbride
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.