我有一些大的日誌/轉儲與SOAP(1line沒有包裝)。 對於第一次我做了一些簡單的選擇串那樣:如何在Powershell中分割不規則字符串?
$where = "D:\log\Test\"
$what = Get-ChildItem $where -Filter "*.txt"
$regex= "(?=<\?xml).*(Envelope>)"
$Path="d:\Log\"
$Result = "D:\Log\wynik2.log"
$string = select-string -Path $what -Pattern $regex
$string
結果是這樣的:
D:\log\Test\test1.txt:1:g .vI.Y....(A..P.......<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">some text1</soap:Body></soap:Envelope>
D:\log\Test\test1.txt:2:g .vJ.YiB..(...P....R..<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">some text2</soap:Body></soap:Envelope>
...
D:\log\Test\test1.txt:4000:g .vL.Yb...'...P.......<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">some text2</soap:Body></soap:Envelope>
我怎麼能放下一切究竟是不是我的SOAP(例如部分:d:\日誌\ Test \ test1.txt:4000:g .vL.Yb ...'P .......)
謝謝我無法得到這個正則表達式^。*?(<\?xml) - 這改變了一切。 – tadamsky