选择 - 弦乐-Context,并在数据中找到电子邮件地址



我有一个文本文件,其中此数据的变化('svc'和之前的日期之后的数字以及文本主体以及文本主体)将出现多次。我可以捕获数据字符串,但是一旦完成,我需要在该数据中找到一个电子邮件地址。该电子邮件可能会出现在任何第4期至9行的上下文中。我似乎无法弄清楚如何隔离数据并将其设置为变量,因此可以捕获。

Select-String $WLDir -pattern '(d{2}:d{2}) - (d{2}:d{2})(PMT[S|T]d{8})' -Context 0,9 | ForEach-Object {
        $StartTime=[datetime]::ParseExact($_.Matches.Groups[1].Value,"HH:mm",$null)
        $EndTime=[datetime]::ParseExact($_.Matches.Groups[2].Value,"HH:mm",$null)
        $ElapsedTime = (NEW-TIMESPAN –Start $StartTime –End $EndTime).TotalHours
        $Email = Select-String $_. -pattern '(b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b)'
    [PSCustomObject]@{
        SO = $_.Matches.Groups[3].Value
        Topic = $_.Context.PostContext[0]
        Status = $_.Context.PostContext[1]
        ElapsedHrs = $ElapsedTime
        Email = $Email
    }
} | Export-Csv $ExportCsv -NoTypeInformation

我的示例文件是这样的:

  09:45 - 10:15SVC1234567 | Sev8 |437257 | COMPANY | Due: 12/28/2016
  WORK TITLE
  - - Preferred Customer (Y/N): Y Phone: 000-000-0000 ANY Hardware (Y/N): N 
  DATA on file (Y/N/NA): Y Contact: Person Name Full Address: 1234 PANTS 
  XING, RM/STE 100,NEWARK, NJ, 00000 - Hours: 8-5 Issue: Install admin 
  and others Fax Number: NA (required for all cases sent to LOCATION or 
  LOCATION_EXCPT Provider Groups) E-Mail address: email@location.com the 
  customer speak English? yes Escalation Approved By (Name/ID): Guy 
  aljdfs ITEM Product: PRODUCTNAME Group:THIS ONE Include 
  detailed notes below, including reason for severity: SCHEDULED WORK 
  ------------------------------ NOTES: -Cx requesting a tech on site -Cx 
  wants to install WS and wants to be assisted in other concerns

我尝试使用$Email = Select-String $_. -pattern '(b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b)'$Email = Select-String $_.WLDir -pattern '(b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b)'$Email = Select-String $_.Context -pattern '(b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b)'在上下文中捕获电子邮件,但无法弄清楚如何回电上下文以搜索电子邮件地址。我也很有可能做错了。有人知道我如何捕获它并将其设置为变量吗?

尝试以下:

$content = gc -path $path -Raw | Out-String
$regex1 = [regex]"w+@w+.w+"
$regex2=[regex]"(?ms)(d{2}:d{2}) - (d{2}:d{2})(D+)(d+)(.*)"
$content | Select-String -pattern $regex2 | %{
$startTime = [datetime]::ParseExact(($regex2.Matches($content) | %{$_.Groups[1].Value}),"HH:mm",$null) 
$endTime = [datetime]::ParseExact(($regex2.Matches($content) | %{$_.Groups[2].Value}),"HH:mm",$null) 
$elapsedTime = (NEW-TIMESPAN –Start $startTime –End $endTime).TotalHours
$code = "PMT" + ($_.Matches.Groups[4].value) 
$remainingString = $_.Matches.Groups[5].Value
$topic = $remainingString.split("`n")[1] 
$status = $remainingString.split("`n")[2] 
$email = $regex1.Matches($remainingString).Value    
[PSCustomObject]@{
        SO = $code
        Topic = $topic
        Status = $status
        ElapsedHrs = $elapsedTime
        Email = $email
    }
} | Export-Csv "res.csv" -NoTypeInformation

,因为我从未找到捕获此信息的准确方法,所以我决定将所有第0-9行捕获到状态中。在Excel表上,我正在使用=IF(O6="","",TRIM(RIGHT(SUBSTITUTE(LEFT(O6,FIND(" ",O6&" ",FIND("@",O6))-1)," ",REPT(" ",LEN(O6))),LEN(O6))))的此页面的计算将数据从" O"列到" Q"列的列中。感谢大家的帮助。

相关内容

  • 没有找到相关文章

最新更新