0

I have a csv file like:

020;1;1;1
030;1;1;1
020;1;2;1
040;1;1;1

Now I want to import-csv the values from the first column and value 020.

I tried:

Import-csv "path/to/file" | Where-Object {$_.[0] -eq "020"

I get a missing Value error.

Can anyone help?

1 Answer 1

2

You have three issues there:

  • The file is not comma separated, but semicolon. Use -Delimiter ';' in Import-Csv.
  • The file is missing header (column names) information. Use -Header c1,c2,c3,c4 or appropriate column names to specify those.
  • Filtering should be done by column name, something like c1 -eq '020'

So, your full command should be:

Import-Csv 'path/to/file' -Header c1,c2,c3,c4 -Delimiter ';' | Where-Object c1 -eq '020'
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, that seems to work. One last problem: When I want to query for c1 and c3 how can I do that? code |Where-Object c1 -eq '020 -and c3 -eq '1' @Igor Please help
code |? c1 -eq '020' |? c3 -eq '1' or code |? { $_.c1 -eq '020' -and $_.c3 -eq '1' }

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.