Regex Powershell CSV解析然后将数据字符串从;“数据”;列转换为适当的逗号分隔的全等列
我需要解析数据列并将适当的字符串移动到适当的列中,如下所示。我需要你的帮助。有人吗 CSV文件:Regex Powershell CSV解析然后将数据字符串从;“数据”;列转换为适当的逗号分隔的全等列,regex,powershell,csv,Regex,Powershell,Csv,我需要解析数据列并将适当的字符串移动到适当的列中,如下所示。我需要你的帮助。有人吗 CSV文件: "Data","Application","Event Date","Heartbeat Events","Audit Events","Action" "Application One 05-MAR-2018 12 8 Follow-up required ",,,,, "Application Two UK 05-MAR-2018 19 164 Follow-up required ",,
"Data","Application","Event Date","Heartbeat Events","Audit Events","Action"
"Application One 05-MAR-2018 12 8 Follow-up required ",,,,,
"Application Two UK 05-MAR-2018 19 164 Follow-up required ",,,,,
"Application South Africa Three 05-MAR-2018 17 41 Follow-up required ",,,,,
因此,每一行都位于数据列中。有36个应用程序,但它们并非每天都发出警报。应用程序字符串应解析为“应用程序”列,日期字符串应解析为“事件日期”列,下一个数字应属于“心跳事件”列,等等
我花了几个星期才走到这一步。这是一个破碎的VB脚本项目,我承诺将其带到Powershell。这些数据是我从本地.htm文件(Chrome)中获取的。原始的csv文件是巨大的,里面有很多东西。正如你所看到的,我设法把它过滤到了三四行
最后,我需要阅读一个包含应用程序名称和应用程序所有者电子邮件地址的文本文件,脚本将向那些应用程序所有者发送一条消息,显示“需要跟进”。脚本每天运行,每周7天
## See the regex on https://regex101.com/r/gapKWC/1
$CSV = import-csv .\test.csv
$RE=[regex]"^(.*?) (\d{2}-[A-Z]{3}-\d{4}) (\d+) (\d+) (.+)$"
ForEach($Row in $CSV){
If ($Row.Data -Match $RE){
$Row.Application = $Matches[1]
$Row.'Event Date' = $Matches[2]
$Row.'Heartbeat Events' = $Matches[3]
$Row.'Audit Events' = $Matches[4]
$Row.Action = $Matches[5]
}
}
$CSV
样本输出:
Data : Application One 05-MAR-2018 12 8 Follow-up required
Application : Application One
Event Date : 05-MAR-2018
Heartbeat Events : 12
Audit Events : 8
Action : Follow-up required
Data : Application Two UK 05-MAR-2018 19 164 Follow-up required
Application : Application Two UK
Event Date : 05-MAR-2018
Heartbeat Events : 19
Audit Events : 164
Action : Follow-up required
Data : Application South Africa Three 05-MAR-2018 17 41 Follow-up required
Application : Application South Africa Three
Event Date : 05-MAR-2018
Heartbeat Events : 17
Audit Events : 41
Action : Follow-up required
正则表达式?
Import-Csv
cmdlet是否有问题?