【发布时间】:2022-01-11 14:01:45
【问题描述】:
代码:
$file= Get-Content "C:\Users\phm4\Desktop\source\status.txt" | select -first 18
$new=$file | select -Skip 12
$nospace=($new)-replace '\s'
$nospace | Out-File new1.txt
import-csv new1.txt -Delimiter "|" | export-csv csvfile.csv
样本数据:
1|10.9.7.73|-A--|0|505k|505k|2.4T/52.7T(5%)|L3:1.5T
2|10.9.7.74|OK|0|608k|608k|2.4T/52.7T(5%)|L3:1.5T
3|10.9.7.75|OK|0|626k|626k|2.4T/52.7T(5%)|L3:1.5T
4|10.9.7.76|OK|0|0|0|2.4T/52.7T(5%)|L3:1.5T
5|10.9.7.77|OK|0|0|0|2.4T/52.7T(5%)|L3:1.5T
6|10.9.7.78|OK|0|398k|398k|2.4T/52.7T(5%)|L3:1.5T
【问题讨论】:
-
为什么不从一开始就使用
$file= Import-Csv -Path "C:\Users\phm4\Desktop\source\status.txt" -Delimiter '|'? -
问题是什么?当前方法的表现如何?
标签: windows powershell csv export-to-csv