我在逗号上拆分csv并取下第6个单元格:
Get-Content .\BSEG_EXPORT.csv | foreach { $_.Split(",")[6] }
但是,这会返回很多空字符串(当前行不匹配):
""
""
"something"
""
""
如何在输出中省略""
?所以:
"something"
我试过
Get-Content .\BSEG_EXPORT.csv | foreach { $a = $_.Split(",")[6] } | Where { $a -ne "" }
但这不起作用。
答案 0 :(得分:1)
怎么样:
Get-Content .\BSEG_EXPORT.csv | foreach {
$cell = $_.Split(",")[6]
if ($cell -ne '""' ) { write-output $cell }
}
答案 1 :(得分:1)
以这种方式尝试:
Get-Content .\BSEG_EXPORT.csv | foreach { $_.Split(",")[6] -ne '""'}