我有一个包含oracle bi发布者报告的文件夹
Folder/Usage Trend Report.xdmz
Folder/Usage Summary Report.xdmz
Folder/Charge Trend Report.xdmz
Folder/Consolidation Reports.xdmz
Folder/Charge Summary Report.xdmz
每个报告都像zip文件,包含一些文件
_datamodel.xdm
~metadata.meta
security.xml
我想创建一个批处理文件,搜索所有_datamodel.xdm文件以查找文字(例如INVOICE_NBR或invoice_nbr) 输出将类似于
Report Name Literal Usages
Consolidation Reports.xdmz INVOICE_NBR 1
有人帮我这么做吗?
由于
答案 0 :(得分:0)
将来,请展示您尝试自行解决问题的方法,以及您遇到问题的地方。这一次,我发现挑战很有趣,所以我为你开了一个开头。这是Batch + PowerShell混合脚本。保存它的.bat扩展名和盐味。请注意,执行字符串计数的regexp对象使用区分大小写匹配;所以“INVOICE_NBR”在搜索“invoice_nbr”时不会增加计数。
<# : batch portion
@echo off & setlocal
set "outerfile=*.xdmz"
set "innerfile=_datamodel.xdm"
set "search=invoice_nbr"
rem // re-launch self with PowerShell interpreter
powershell "iex (${%~f0} | out-string)"
goto :EOF
: end batch / begin PowerShell hybrid chimera #>
add-type -as System.IO.Compression.FileSystem
# // encapsulate loop into a collection for select | format-table
&{ foreach ($archive in (gci $env:outerfile)) {
# // create a temporary directory within %temp%
$tempdir = New-Item -path $env:temp -name ([Guid]::NewGuid()) -type dir
[IO.Compression.ZipFile]::ExtractToDirectory($archive, $tempdir)
# // For each innerfile found within the zip archive...
gci -path $tempdir -filter $env:innerfile -recurse | %{
new-object PSObject -property @{
"Report Name" = $archive.Name
"Usages" = ([regex]::Matches((gc $_.FullName | out-string), $env:search)).count
"Literal" = $env:search
}
}
Remove-Item $tempdir -recurse -force
} } | select "Report Name",Literal,Usages | format-table -auto
示例输出:
Report Name Literal Usages
----------- ------- ------
Usage Summary Report.xdmz invoice_nbr 2
Usage Trend Report.xdmz invoice_nbr 2
如果您希望在敏感匹配中使用case- ,请将以下内容作为第三个参数添加到[regex]::Matches()
函数中:
[Text.RegularExpressions.RegexOptions]::IgnoreCase