Nick Collins
asked on
Count on Txt File
Good Morning,
Just a simple request I have a text file that has various header records and I want to be able to do a count on the header record ‘Order Number’.
Then output to a text file and sorted in A to Z with a total at the bottom. Example below
Order Number. Total
GB088776 10
VB66666. 12
HF56778. 6
Total 28
Just a simple request I have a text file that has various header records and I want to be able to do a count on the header record ‘Order Number’.
Then output to a text file and sorted in A to Z with a total at the bottom. Example below
Order Number. Total
GB088776 10
VB66666. 12
HF56778. 6
Total 28
ASKER
I am getting an error with this code...
At D:\iauditor_exports_folder\ExportData\Run.ps1:3 char:37
+ ( Write Output "Order NumnerˋtTotal"
+ ~
Missing closing ')' in expression.
At D:\iauditor_exports_folder\ExportData\Run.ps1:4 char:3
+ $data | % { Write-Output "$($_.Name)ˋt$($_.Count)" }
+ ~~~~~
Unexpected token '$data' in expression or statement.
At D:\iauditor_exports_folder\ExportData\Run.ps1:6 char:1
+ ) | Out-File C:\output.csv
+ ~
Unexpected token ')' in expression or statement.
At D:\iauditor_exports_folder\ExportData\Run.ps1:6 char:3
+ ) | Out-File C:\output.csv
+ ~
An empty pipe element is not allowed.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInExpression
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't give me any points for this.
Missing a hyphen ("-") in Write-Output in line 3.
Missing a hyphen ("-") in Write-Output in line 3.
ASKER
The grand total on the bottom is not working of the powershell is not correct
Corrected script:
$data = Import-CSV C:\input.csv | Group-Object 'Order Number' -NoElement | Sort Name
$total =($data | measure-object Count -Sum).Sum
$( Write-Output "Order Numner`tTotal"
$data | % { Write-Output "$($_.Name)`t$($_.Count)" }
Write-Output "Total`t$total"
) | Out-File C:\output.csv
Open in new window