View Single Post
Old 10-12-2008   #4 (permalink)
dikex


 
 

Re: How do I filter rows in one csv file matching a value in another

Quote  Quote: Originally Posted by Art-De View Post
Hi,

Can someone please help me get the following done in Powershell:

I'v got this in a csv file (RefVal.csv):

RefVal
01
02
07
05
09
03

and I'v got this in another csv file (RefValContent.csv):

RefValC,Col1,Col2
01,Col1Content1,Col2Content1
02,Col1Content2,Col2Content2
03,Col1Content3,Col2Content3
04,Col1Content4,Col2Content4
05,Col1Content5,Col2Content5
06,Col1Content6,Col2Content6
07,Col1Content7,Col2Content7
08,Col1Content8,Col2Content8
09,Col1Content9,Col2Content9

The csv output I'm trying to pipe out:

RefValC Col1 Col2
------- ---- ----
01 Col1Content1 Col2Content1
02 Col1Content2 Col2Content2
03 Col1Content3 Col2Content3
05 Col1Content5 Col2Content5
07 Col1Content7 Col2Content7
09 Col1Content9 Col2Content9

I'v tried some variations like the following but without success.

PS >Import-Csv RefValContent.csv | ?{$_.RefValC -match $(Import-CSV
refval.csv | %{$_.RefVal})} | export-csv output.csv

Thanks!

Art-De
hi,
maybe it's because of "-match"

Code:
 
Import-Csv RefValContent.csv | ?{$(Import-CSV refval.csv | %{$_.RefVal}) -match $_.RefValC}
i can't tell you why , but it can work

object -match array (wrong?)
array -match object (right?)
maybe...maybe...
My System SpecsSystem Spec