亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標(biāo)題:
nginx的日志格式字段替換
[打印本頁]
作者:
opiopuiopoi
時間:
2016-05-17 14:27
標(biāo)題:
nginx的日志格式字段替換
本帖最后由 opiopuiopoi 于 2016-05-17 14:32 編輯
大家熟悉的nginx的配置文件中,日志格式的片段:
log_format main
'$remote_addr,$remote_user,[$time_local],"$request",'
'$status $body_bytes_sent,"$http_referer",
"$request_time"'
;
想把藍(lán)色字體的字段替換為我想要的格式,紅色的保留。
比如替換為:
log_format main
'$remote_addr $remote_user [$time_local] "http://$host" "$request" '
'$status $body_bytes_sent "$http_referer" "$http_user_agent" "$HTTP_X_UP_CALLING_LINE_ID"
';
總之原來的格式字段不固定,行數(shù)也不固定,替換為我想要的格式。
作者:
lll1985911
時間:
2016-05-17 14:50
本帖最后由 lll1985911 于 2016-05-17 15:04 編輯
paste -d' ' -s a.txt | sed -r -e 's/ +/ /g' -e 's/,/ "http:\/\/$host" /3' -e 's/,/ "$http_user_agent"/5' -e 's/request_time/HTTP_X_UP_CALLING_LINE_ID/' -e 's/,/ /g' -e "s/' '/'\n\t\t'/"
復(fù)制代碼
作者:
opiopuiopoi
時間:
2016-05-17 15:44
感謝回復(fù)!
可能是我沒說清楚,再解釋一下:
藍(lán)色字體的具體字段內(nèi)容我們完全沒有必要管它,我們只是替換它。
paste命令的方式也不妥,因為我貼出的文本只是nginx.conf 里的一個片段,paste 一個文件就沒有必要了。
回復(fù)
2#
lll1985911
作者:
lll1985911
時間:
2016-05-17 16:22
回復(fù)
3#
opiopuiopoi
你要替換成什么東西?
作者:
opiopuiopoi
時間:
2016-05-17 17:36
sed -e ':label; /log_format\s*main/,/;/ { /;/! { $! { N; b label }; }; s/log_format.*;/abcasdfasdfa/; }' a.txt
這個暫時完成了替換。
作者:
sunzhiguolu
時間:
2016-05-17 17:38
回復(fù)
5#
opiopuiopoi
能說下思路嗎? 謝謝...
作者:
moperyblue
時間:
2016-05-22 18:12
本帖最后由 moperyblue 于 2016-05-22 18:15 編輯
more my_fmt.txt
'$remote_addr $remote_user [$time_local] "http://$host" "$request" '
'$status $body_bytes_sent "$http_referer" "$http_user_agent" "$HTTP_X_UP_CALLING_LINE_ID" ';
more file
xx
log_format main '$remote_addr,$remote_user,[$time_local],"$request",'
'$status $body_bytes_sent,"$http_referer",
"$request_time"';
oo
sed '/log_format\s*main\s*/{s//&\n/;:a;N;/;/!{s/\n//2;ta};s/\n.*//;h;s/.*/cat my_fmt.txt/e;x;G;s/\n//}' file
xx
log_format main '$remote_addr $remote_user [$time_local] "http://$host" "$request" '
'$status $body_bytes_sent "$http_referer" "$http_user_agent" "$HTTP_X_UP_CALLING_LINE_ID" ';
oo
復(fù)制代碼
歡迎光臨 Chinaunix (http://www.72891.cn/)
Powered by Discuz! X3.2