我正在尝试格式化输出,如下所示:
源文件:
a.txt
:
website is : "rent.com/test"
b.txt
:
"rent.com/"
c.txt
:
rent.com
输出应为(格式:file ~ linenumber~ line ~matched value
):
D:\test\a.txt~1~website is : "rent.com/test"~rent.com/test"
我得到的输出:
D:\test\a.txt~1~website is : "rent.com/test"~System.Text.RegularExpressions.Match[] D:\test\b.txt~1~"rent.com/"~System.Text.RegularExpressions.Match[]
代码:
$pat = @('rent.com/.\+"')
$files = Get-ChildItem "D:\test\*.*" -Recurse
$files |
Select-String -Pattern $pat |
%{ "{0}~{1}~{2}~{3}" -f $_.Path, $_.LineNumber, $_.Line ,$_.Matches } |
Out-File "D:\output\result.txt"
两个问题:
rent.com/.\+
与字符串"rent.com/"
匹配?