Avoid line breaks when using out-file

前端 未结 2 1397
刺人心
刺人心 2021-01-07 22:27

I\'m getting a little frustrated on a little PowerShell script I\'m writing.

Basically I loop through text files to check every line against an array of regular expr

2条回答
  •  -上瘾入骨i
    2021-01-07 22:47

    Keep in mind that Select-String outputs MatchInfo objects and not strings - as is shown by this command:

    gci $logdir -r *.txt | gc | select-string $patterns | format-list *
    

    You are asking for an implicit rendering of the MatchInfo object to string before being output to file. For some reason I don't understand, this is causing additional blank lines to be output. You can fix this by specifying that you only want the Line property output to the file e.g.:

    gci $logdir -r *.txt | gc | select-string $patterns | %{$_.Line} | 
        Out-File $csvpath -append -width 1000
    

提交回复
热议问题