Search value in a CSV file and do something with it!

Welcome Forums General PowerShell Q&A Search value in a CSV file and do something with it!

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
2 years, 8 months ago.

  • Author
    Posts
  • #35741

    Inactive
    Points: 0
    Rank: Member

    Hi PowerGEEKS,

    I want te following thing to do

    I have a list of customers and prices view example below

    number Price
    10071 30.00
    10071 5.00
    10071 4.00
    10071 0.00
    10071 4.00
    10071 3.75
    10071 15.89
    10071 0.00
    10297 0.00
    10297 0.00
    10297 0.00
    10297 0.00

    Table 2
    number Totalpricel
    10071 46,75
    10297 0

    I want to import a CSV file then select the number ( customer number) inc. price and make a total price of it in another CSV file. Is this possible? Or do I need to use another programming language?

    import-csv -path C:\temp\gegevens1.csv | select-object custumernumber, price | export-csv -path.

    I hope my question is clear

    Kind regards,

    Gijs Liefers (Dutch name)

  • #35742

    Participant
    Points: 10
    Rank: Member
    # Export customer and price totals
    $groups = Import-Csv "C:\temp\gegevens1.csv" | Group-Object -Property customernumber
    $groups | ForEach-Object {$measure = $_.group | Measure-Object -Property price -Sum 
    [pscustomobject]@{'customer number' = $_.name;
                    'total price'=$measure.Sum}} | 
    Export-Csv -Path "C:\temp\gegevens1_total.csv" -NoTypeInformation -Append
    

The topic ‘Search value in a CSV file and do something with it!’ is closed to new replies.