我有一个这样的文件:
<LocationMatch ^/raframework>
SetHandler weblogic-handler
WeblogicCluster xlytwv02-pub.sherwin.com:45330
WLIOTimeoutSecs 6000
Idempotent OFF
</LocationMatch>
<LocationMatch ^/biplus_webservices>
SetHandler weblogic-handler
WeblogicCluster xlytwv02-pub.sherwin.com:45330
</LocationMatch>
<LocationMatch ^/hr>
SetHandler weblogic-handler
WeblogicCluster xlytwv02-pub.sherwin.com:8530
WLIOTimeoutSecs 18000
Idempotent OFF
WLSocketTimeoutSecs 18000
</LocationMatch>
我需要修改它,使其看起来像:无论值
<LocationMatch ^/raframework>
raframework:SetHandler weblogic-handler
raframework:WeblogicCluster xlytwv02-pub.sherwin.com:45330
raframework:WLIOTimeoutSecs 6000
raframework:Idempotent OFF
</LocationMatch>
<LocationMatch ^/biplus_webservices>
biplus_webservices:SetHandler weblogic-handler
biplus_webservices:WeblogicCluster xlytwv02-pub.sherwin.com:45330
</LocationMatch>
<LocationMatch ^/hr>
hr:SetHandler weblogic-handler
hr:WeblogicCluster xlytwv02-pub.sherwin.com:8530
hr:WLIOTimeoutSecs 18000
hr:Idempotent OFF
hr:WLSocketTimeoutSecs 18000
</LocationMatch>
答案1
awk
跟踪<LocationMatch.../>
值并为中间行添加前缀的过滤器应该可以工作:
awk '/^<LocationMatch \^/ {
print $0
m=substr($2,3,length($2)-3) ":"
next
}
/^<\/LocationMatch>/ { m="" }
{ print m $0 }
'
在这个循环中m
是前缀(包括:
)。我们将其设置为在线<LocationMatch>
并清除它</LocationMatch>
。它们之外的任何行(包括空行以及之前/之后的任何行)都应保持不变。