简体   繁体   English

PowerShell:在两个单词之间查找文本

[英]PowerShell: Find Text between two Words

I need to find out, if there are maxThreads and/or maxConnections configured in the connector port 8080 of tomcat. 我需要了解一下,tomcat的connector port 8080中是否配置了maxThreads和/或maxConnections

example: 例:

<Connector port="8080" protocol="HTTP/1.1"
       maxThreads="600"
       maxConnections="3000"
           connectionTimeout="20000"
           redirectPort="443" />

I tried it with regex but poorly failed. 我用regex尝试过,但失败极少。

$file = Get-Content "D:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\server.xml"
$pattern = "(?<=.*protocol=""HTTP/1.1"")\w+?(?=connectionTimeout=""20000"".*)"
$Opts = [Regex]::Match($file, $pattern)

Thanks ahead 提前谢谢

this is straightforward 这很简单

PS>[xml]$x=gc "D:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\server.xml" 
PS>$x.xml.Connector.maxConnections   
3000         
PS>$x.xml.Connector.maxThreads 
600            

if you have several connectors you could do 如果您有几个连接器,您可以做

$x.xml.Connector | ?{ $_.port -eq "8080"} |select maxthreads  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM