如果第一行为0或为空,如何跳过第一行

时间:2015-04-13 19:35:04

标签: powershell powershell-v4.0

get-childitem -path $csvfolder *.inv | get-content | add-content $outputfile

我想跳过inv文件的第一行,如果它是0,但如果只有1行,那么我想复制它。

有关如何执行此操作的任何建议吗?

1 个答案:

答案 0 :(得分:1)

我认为这是您正在寻找的基于测试的内容。

Get-ChildItem -path $csvfolder *.inv | Select -Expand Fullname | ForEach-Object{
    $singleFile = @(Get-Content $_)
    If($singleFile[0] -eq "0" -and $singleFile.Count -gt 1){
        $singleFile | Select-Object -Skip 1
    } Else {
        $singleFile
    }
} | add-content $outputfile

如果$singleFile的第一行是0且文件有多行,则跳过0。我觉得你可能正在寻找其中有0的行,但你可以告诉我这是否适合你。否则文件只是正常发送到管道。