0

I receive a CSV File everyday that has information I need, but i have to filter rows base on a different criteria for each row.

eg csv.

Name,Age,Date,Code
John,22,12/12/2020,5
Smith,16,12/01/2021,2
Jake,27,1/01/2020,1
Alice,18,2/02/2019,4
Fort,27,2/09/2021,2
Kevin,26,22/09/2019,5

I would like:

  1. Remove all ages 18 and below in column 2
  2. remove any dates past 2020 in column 3
  3. Remove any codes that are 5 in column 5

My Result should be

Name,Age,Date,Code
Jake,27,1/01/2020,1
Fort,27,2/09/2021,2
2
  • 1
    hi, interesting, perhaps a filter like stackoverflow.com/questions/38479625/… Commented Feb 11, 2021 at 1:12
  • Let us know if you were able to make progress using the link IronMan provided or if you still need assistance Commented Feb 11, 2021 at 3:19

1 Answer 1

2
$csv = @"
Name,Age,Date,Code
John,22,12/12/2020,5
Smith,16,12/01/2021,2
Jake,27,1/01/2020,1
Alice,18,2/02/2019,4
Fort,27,2/09/2021,2
Kevin,26,22/09/2019,5
"@ | ConvertFrom-Csv

$csv.where{
    ($_.Age -le 18,
    [datetime]::ParseExact($_.Date, 'd/MM/yyyy', $null) -ge [datetime]::ParseExact('01/01/2020', 'dd/MM/yyyy', $null),
    $_.Code -eq 5)
}

Try it online!

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.