Author Posts

August 10, 2016 at 11:43 am

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!!

August 10, 2016 at 11:53 am

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

August 10, 2016 at 2:02 pm

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