Text Manipulation using PowerShell

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

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]+)’ ){
‘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.

Thanks, it was perfect. :slight_smile: