0

My problem is quite simple, I have a csv file with a format as such:

Client   Status       Goal       Project
A         Done         Done       Waiting
B         Finished     Done       Cancelled
C                      Waiting    Finished
D         Done         Done       Done

Now, my queestion is simple, I want for example, to update a value on the column 'Goal' that matches client 'B'

I know that I can do import-csv and using calculated properties modify a column, but I have no idea how can I modify a specific row on a column that matches another row in another column and that is my question. I want for example to change Waiting to Finished client C, or change cancelled to waiting on client B.

1
  • error on my example, not real headers. Commented Oct 30, 2019 at 16:00

1 Answer 1

1

You could do that something like this:

$csv = Import-Csv 'D:\clientprojects.csv'
($csv | Where-Object {$_.Client -eq 'C'}).Goal = 'Finished'
($csv | Where-Object {$_.Client -eq 'B'}).Project = 'Waiting'

#output on console
$csv

# write to new CSV file
$csv | Export-Csv -Path 'D:\clientprojects-updated.csv' -NoTypeInformation

output on console:

Client Status   Goal     Project 
------ ------   ----     ------- 
A      Done     Done     Waiting 
B      Finished Done     Waiting 
C               Finished Finished
D      Done     Done     Done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.