需要提取8&;使用PowerShell的40000封电子邮件中的9位文件号
我试图从40000封已保存为.txt文件的电子邮件中提取8位和9位的文件号。文件编号可以出现在电子邮件中的任何位置(这不是标准格式),但长度应始终为8或9位。文件编号也可以几种不同的方式格式化,如:xxx-xx-xxxx、xxx-xx-xxxx、xxxxxxxx、8位#的:YY-YYY-YYY、YY-YYY-yyyy。我创建了一个PowerShell脚本,用于读取文本文件,提取与所述模式匹配的文件号,并将其创建并保存到.csv文件中 问题:如果行中有任何文本继续处理文件,则脚本无法获取文件。它还获取其他文本(在文件#后的同一行上)。我只需要与设定模式完全匹配 解决方案不需要在PowerShell中,如果vbscript中有更好的解决方案,我也愿意这样做 当前脚本如下:需要提取8&;使用PowerShell的40000封电子邮件中的9位文件号,powershell,vbscript,extraction,Powershell,Vbscript,Extraction,我试图从40000封已保存为.txt文件的电子邮件中提取8位和9位的文件号。文件编号可以出现在电子邮件中的任何位置(这不是标准格式),但长度应始终为8或9位。文件编号也可以几种不同的方式格式化,如:xxx-xx-xxxx、xxx-xx-xxxx、xxxxxxxx、8位#的:YY-YYY-YYY、YY-YYY-yyyy。我创建了一个PowerShell脚本,用于读取文本文件,提取与所述模式匹配的文件号,并将其创建并保存到.csv文件中 问题:如果行中有任何文本继续处理文件,则脚本无法获取文件。它还
$Num = @()
$Num += Select-String -Path "$PSSCRIPTROOT\text.txt" -Pattern '\d{8}$|^\d{2}\s\d{3}\s\d{3}$|^\d{2}-\d{3}-\d{3}$'
$Num += Select-String -Path "$PSSCRIPTROOT\text.txt" -Pattern '\d{9}$|^\d{3}\s\d{2}\s\d{4}$|^\d{3}-\d{2}-\d{4}$'
ForEach ($Matches in $Num){
$Found = $Matches.ToString().Split(":")
$o = new-object PSObject
$o | add-member NoteProperty "FoundOnLine" $Found[2]
$o | add-member NoteProperty "Number" $Found[3]
$o | export-csv "$PSscriptroot\FoundNumbers.csv" -notypeinformation -Append
Write-Output $o
请帮忙 这实际上应该可以做到
$File = "$PSSCRIPTROOT\text.txt"
$Pattern = '\d\d(\s|-)*\d(\s|-)*\d(\s|-)*\d{4,5}'
Select-String -Path $File -Pattern $Pattern -AllMatches |
Select-Object -ExpandProperty Matches |
Select-Object -ExpandProperty Value