如何在 Powershell 中拆分 ics 日历事件
How to split ics calendar events in Powershell
我正在尝试编写一个脚本来合并两个 Google 日历 ics 文件并删除重复的事件。使用 Powershell 我尝试了以下
$cal1 = get-content ".\googlecalendar.ics"
$calarr = $cal1 -replace ("BEGIN.VEVENT","###EVENTDELIM###`r`nBEGIN.VEVENT") -split ("###EVENTDELIM###")
$calarr[4]
$calarr[4] 产生 METHOD:PUBLISH
但是,这会生成文件的逐行字符串数组。我希望数组中的每个 object 都是一个 multi-line 字符串。
我还尝试了另一种使用正则表达式的解决方案。
$cal1 = get-content ".\googlecalendar.ics"
$calarr = ([Regex]'BEGIN:VEVENT([\s\S]*?)END:VEVENT').Matches($cal1).Value
$calarr[4]
$calarr[4] 产生 BEGIN:VEVENT DTSTART:20090929T220000Z DTEND:20090929T230000Z DTSTAMP:20180326T211259Z UID:dfjkadfawerjj14543@google.com CREATED:20090929T204053Z 描述:LAST-MODIFIED:20091014T094735Z 位置:SEQUENCE:0 STATUS:CONFIRMED SUMMARY:intv TRANSP:OPA
队列 END:VEVENT
但是该解决方案混淆了各个行结尾。每个键和值对都应该在他们自己的行上。
在 Powershell 中进行 sub-string 选择然后将它们转换为数组同时保留 non-printing 字符和 sub-string headers 的正确方法是什么?
However, this produces an array of the line by line strings of the file. I am expecting each object in the array to be a multi-line string.
将您的数组发送到 Out-String
以获得 multi-line 字符串。
我明白了。我忘记了 Powershell 对带有 get-content 的文本文件做了奇怪的事情。当我强制 PS 使用以下
读取文本文件内容时,我的正则表达式解决方案开始保留行尾
[string]$cal1 = get-content ".\googlecalendar.ics" -Raw
我忘了 Powershell 会自然地将文本文件转换为行数组。
我正在尝试编写一个脚本来合并两个 Google 日历 ics 文件并删除重复的事件。使用 Powershell 我尝试了以下
$cal1 = get-content ".\googlecalendar.ics"
$calarr = $cal1 -replace ("BEGIN.VEVENT","###EVENTDELIM###`r`nBEGIN.VEVENT") -split ("###EVENTDELIM###")
$calarr[4]
$calarr[4] 产生 METHOD:PUBLISH
但是,这会生成文件的逐行字符串数组。我希望数组中的每个 object 都是一个 multi-line 字符串。
我还尝试了另一种使用正则表达式的解决方案。
$cal1 = get-content ".\googlecalendar.ics"
$calarr = ([Regex]'BEGIN:VEVENT([\s\S]*?)END:VEVENT').Matches($cal1).Value
$calarr[4]
$calarr[4] 产生 BEGIN:VEVENT DTSTART:20090929T220000Z DTEND:20090929T230000Z DTSTAMP:20180326T211259Z UID:dfjkadfawerjj14543@google.com CREATED:20090929T204053Z 描述:LAST-MODIFIED:20091014T094735Z 位置:SEQUENCE:0 STATUS:CONFIRMED SUMMARY:intv TRANSP:OPA 队列 END:VEVENT
但是该解决方案混淆了各个行结尾。每个键和值对都应该在他们自己的行上。
在 Powershell 中进行 sub-string 选择然后将它们转换为数组同时保留 non-printing 字符和 sub-string headers 的正确方法是什么?
However, this produces an array of the line by line strings of the file. I am expecting each object in the array to be a multi-line string.
将您的数组发送到 Out-String
以获得 multi-line 字符串。
我明白了。我忘记了 Powershell 对带有 get-content 的文本文件做了奇怪的事情。当我强制 PS 使用以下
读取文本文件内容时,我的正则表达式解决方案开始保留行尾[string]$cal1 = get-content ".\googlecalendar.ics" -Raw
我忘了 Powershell 会自然地将文本文件转换为行数组。