File content manipulation using PS 3.0

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of random commandline random commandline 3 months, 3 weeks ago.

  • Author
    Posts
  • #49814
    Profile photo of Aswin Kumar
    Aswin Kumar
    Participant

    Hello

    I am trying to fetch content from a .dat file specific to a pattern via powershell 3.0. I would like to get the count of number of "OK" under "STATUS" column(Exactly OK) which is an array. Below is the data for reference.

    ———————————————————————————————————————-
    Daily Statistics

    ARP_COUNT ARP_AMOUNT STATUS
    ————— ————— ———-
    1300 1998346.21 OK
    156 24949.19 OK
    350 87107.6 OK
    183222 20988447.31 OK
    2255 1042823.8 NOT_OK

    Total Records
    ———————————————————————————————————————-

    Thanks in advance!!

  • #49818
    Profile photo of Paul Frankovich
    Paul Frankovich
    Participant

    What have you tried so far? Using Get-Content would be a good start.

  • #49862
    Profile photo of random commandline
    random commandline
    Participant

    There may be a better way to do this, but this should work.

    $status = Import-Csv "\\path\to\file.dat" -Delimiter ' ' -Header 'arpcount','arpamount','status' | 
    Select-Object -Property @{n='Status';exp={If ($_.status -eq 'OK'){$_.Status}}}
    $status.status.count
    

You must be logged in to reply to this topic.