Removing blank or lines

Welcome Forums General PowerShell Q&A Removing blank or lines

This topic contains 3 replies, has 4 voices, and was last updated by

 
Participant
1 year, 5 months ago.

  • Author
    Posts
  • #71600

    Participant
    Points: 0
    Rank: Member

    I have read a number of posts on removing blank lines from output but just can't get it to work. I have a file and I want to count the matches in the file. For example, I have "foo" in my file "logfile".

     Select-string -path "c:\cygwin64\tmp\logfile" -pattern "foo"  | Measure-object -line | ft -hidetableheaders
    
       3
    
    

    I have tried things like...

    Select-string -path "c:\cygwin64\tmp\logfile" -pattern "foo"  | Measure-object -line | ft -hidetableheaders | where {$_ -ne " "}
    

    Here, if I save the output to a file I get closer to the results I want..

    
    PS C:\Program Files\Wireshark> Select-string -path "c:\cygwin64\tmp\logfile" -pattern "foo"  | Measure-object -line | ft -hidetableheaders > x.x; cat x.x | where {$_ -ne ""}
        3
    
    

    Any suggestions?

  • #71608

    Participant
    Points: 0
    Rank: Member

    get rid of ft, use select-object
    format-table – for displaying to host, it should be last element of pipeline

  • #71612

    Participant
    Points: 60
    Rank: Member
    (Select-string -path "c:\cygwin64\tmp\logfile" -pattern "foo"  | Measure-object -line).Lines
    
  • #71632

    Participant
    Points: 41
    Rank: Member
    (Get-Content "c:\cygwin64\tmp\logfile"  | where {$_ -like "*foo*"}).count

The topic ‘Removing blank or lines’ is closed to new replies.