我有一个格式为
first:web
last:site
age:99
first:stack
last:overflow
age: 88
我正在尝试将其转换为这种格式
first|last|age
web|site|99
stack|overflow|88
到目前为止,这是我用来在一行中获取所有内容的代码,但我无法弄清楚循环遍历它并打破它的语法
$TextLocation = "data.txt"
$Writefile = "results.txt"
$FileLocation = "C:\Users\"
$SearchStr1 = "First:"
$SearchStr2 = "Last:"
$SearchStr3 = "Age:"
$SearchStr4 = ""
#Get content
$a =Get-Content $TextLocation |
#Find search strings and replace with pipes
Foreach-Object {
$_ -replace $SearchStr1 , "|" `
-replace $SearchStr2, "|" `
-replace $SearchStr3, "|" `
-replace$SearchStr4, "|" `
} |
# join all lines
$a -join ""
#Break after every 4th pipe
谢谢