server
{
listen 80;
server_name www.mcshell.org mcshell.org;
index index.php index.html index.htm;
root /data0/web/mcshell;
error_page 404 =http://www.mcshell.org;
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/(.*)\?*$ /index.php?_route_=$1 last;
}
if ($host != 'www.mcshell.org' ) {
rewrite ^/(.*)$ http://www.mcshell.org/$1 permanent;
}
..
..
{
listen 80;
server_name www.mcshell.org mcshell.org;
index index.php index.html index.htm;
root /data0/web/mcshell;
error_page 404 =http://www.mcshell.org;
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/(.*)\?*$ /index.php?_route_=$1 last;
}
if ($host != 'www.mcshell.org' ) {
rewrite ^/(.*)$ http://www.mcshell.org/$1 permanent;
}
..
..
现在要求提取出
www.mcshell.org mcshell.org /data0/mcshell
这样的对应方式
代码如下
#!/usr/bin/perl
while(<>){
chomp;
if(/server_name\s(.*);/){
print "$1\t";
$paths=<>;
(undef,undef,undef,undef,$server )= split /\s+/,$paths; #填充不需要的行
$pathss=<>;
(undef,undef,$servers )= split /\s+/,$pathss;
print "$servers\n";
}
}
while(<>){
chomp;
if(/server_name\s(.*);/){
print "$1\t";
$paths=<>;
(undef,undef,undef,undef,$server )= split /\s+/,$paths; #填充不需要的行
$pathss=<>;
(undef,undef,$servers )= split /\s+/,$pathss;
print "$servers\n";
}
}
本文转自 mcshell 51CTO博客,原文链接:http://blog.51cto.com/mcshell/480852,如需转载请自行联系原作者