从shell输出中删除子串

时间:2016-03-22 12:22:19

标签: shell sed

我正在尝试使用sed

在我的服务器上获取nginx的版本

我的尝试

nginx -v  | sed -e "s|nginx version: nginx/||"

输出

nginx version: nginx/1.9.12

预期输出

1.9.12

2 个答案:

答案 0 :(得分:0)

nginx将版本打印到stderr,因此您需要重定向输出:

nginx -v 2>&1 | sed -e "s|nginx version: nginx/||"
#        ^ redirect stderr to stdout

答案 1 :(得分:-1)

检查输出样本

nginx version: nginx/1.2.3
built by gcc 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC)
TLS SNI support enabled
configure arguments: --without-http_autoindex_module --without-http_userid_module --without-http_auth_basic_module --without-http_fastcgi_module --without-http_empty_gif_module --with-poll_module --with-http_stub_status_module --with-http_ssl_module --with-ipv6 --with-http_geoip_module
相关问题