1. 程式人生 > >shell 格式化輸出nginx的編譯參數

shell 格式化輸出nginx的編譯參數

nginx參數 linux sed tr awk

命令

nginx -V > nginx.txt
cat -n nginx.txt  | sed -n ‘5,18p‘ | awk ‘{$1="";print $0}‘ 
| sed ‘s/^[ ]*//g‘  | tr ‘\n‘ ‘,‘ | sed -n ‘s/,//gp‘ | tr " " "\n"

結果

configure
arguments:
--user=nginx
--group=nginx
--prefix=/usr/share/nginx
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body
--http-proxy-temp-path=/var/lib/nginx/tmp/proxy
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi
--http-scgi-temp-path=/var/lib/nginx/tmp/scgi
--pid-path=/var/run/nginx.pid
--lock-path=/var/lock/subsys/nginx
--with-http_ssl_module
--with-http_spdy_module
--with-http_v2_module
--with-http_realip_module
--with-http_addition_module
--with-http_xslt_module
--with-http_image_filter_module
--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_gzip_static_module
--with-http_secure_link_module
--with-http_degradation_module
--with-http_stub_status_module
--with-debug
--with-http_sysguard_module
--with-http_upstream_check_module
--with-http_lua_module
--with-http_dyups_module
--with-luajit-lib=/usr/lib
--with-luajit-inc=/usr/include/luajit-2.0

解釋:

awk ‘{$1="";print $0}‘

輸出第2列至最後一列(即排除第一列)

 sed ‘s/^[ ]*//g‘

去掉行首的空格

tr ‘\n‘ ‘,‘ | sed -n ‘s/,//gp‘

去掉換行符,先把換行符替換成逗號(或者#¥%&等),然後再講逗號刪除

shell 格式化輸出nginx的編譯參數