Author Posts

October 25, 2016 at 8:57 am

Hi All,

I have some data in a text file like below :

My requirement is to Find the number of ROWS present between "Daily Load Statistics" and "Total Snags/Duplicates/Dishonors in Database" . For example we can see there are 5 rows (09-AUG-16) so the output should come as 5 Rows. After getting the ROWS Count,I have to check the number of OK's in that rows. it may be OK or Not OK.

Final Output expected :
———————-
Rows Count : 5
No of OK : 4

Kindly let me know if there is any queries

October 25, 2016 at 10:07 am

That might be oversized but I think it does the job:

$SampleTxt = Get-Content -Path C:\Test\Sample.txt
$ParsedResults = foreach ($Line in $SampleTxt) {
	If($Line -match '(\d{2}-[A-Z]{3}-\d{2})\s+(\d{4})\s+(\w*)\s+(L)\s+(\d*)\s+(\d*\.\d*)\s+(\d*)\s+(\d*\.\d*)\s+([A-Z]+)' ){
        [PSCustomObject]@{
            'LOAD_DATE' = $Matches[1]
            'CYCLE_NO' = $Matches[2]
            'TABLE_NAME' = $Matches[3]
            'T' = $Matches[4]
            'EDIRIS_COUNT' = $Matches[5]
            'EDIRIS_AMOUNT' = $Matches[6]
            'CPC_COUNT' = $Matches[7]
            'CPC_AMOUNT' = $Matches[8]
            'STATUS' = $Matches[9]
        }
    }
}
$ParsedResults | Format-Table -AutoSize
$RowsCount = $ParsedResults.Count
$OKCount = ($ParsedResults | ? -Property 'Status' -Value 'OK' -EQ).Count
Write-Host "Rows Count: $RowsCount"
Write-Host "No of OK: $OKCount"

Of course you have to adjust the path for your environment/needs.

October 25, 2016 at 1:33 pm

Thanks, it was perfect. 🙂