所以我正在编写一个 powershell 脚本来帮助对我拥有的数据进行排序,但我需要某种格式的数据。
FN: ORG: Title Tel: Email:
Example A Exam A Exa A EX A EA
Example B Exam B Exa B Ex B EB
但是,我得到的输出是:
FN:Example A
ORG:Exam A
Title:Exa A
Tel: EX A
Email: ExA
FN: Example B
ORG:Exam B
Title: Exa A
Email: EX B
我写的是:
> ls *.vcf|%{cat $_ >>"result.txt"} Get-Content "result.txt" |
> Select-String -Pattern
> '(FN:)|(ORG:)|(TITLE:)|(TEL;WORK;VOICE:)|(EMAIL;)'>>new.csv
我相信每个人都知道,我对此很陌生,并试图自学。任何帮助是极大的赞赏。
您可能正在寻找类似以下的内容:
Get-ChildItem *.vcf |
ForEach-Object {
$oht = [ordered] @{} # Ordered helper hashtable
# Find all lines of interest in the file at hand, split them into
# field name and value, and add to the hashtable.
$_ |
Select-String -Pattern '^(FN|ORG|TITLE|TEL;WORK;VOICE|EMAIL):(.*)' |
ForEach-Object { $oht[$_.Matches[0].Groups[1]] = $_.Matches[0].Groups[2] }
# Convert the hashtable to a custom object that Export-Csv understands
# and output it.
[pscustomobject] $oht
} |
Export-Csv -Encoding utf8 new.csv # Adapt the encoding as needed.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句