I have two files/outputs.
$file1
contains:
Name,Address,Number
$file2
contains:
Name
I'm looking to match those two files on Name and output the entire line from $file1
I have two files/outputs.
$file1
contains:
Name,Address,Number
$file2
contains:
Name
I'm looking to match those two files on Name and output the entire line from $file1
Assuming that your files are CSV files:
Combine Import-Csv
with Where-Object
to filter those lines, with the help of the -in
operator:
Import-Csv $file1 | # Parse the CSV file into objects
Where-Object Name -in (Import-Csv $file2).Name # Filter
Note:
This is a conceptually simple, but potentially slow solution, depending on the size of the input files. More efficient - but more elaborate - solutions are possible.
The filtered CSV rows are output as objects (of type [pscustomobject]
), as parsed by Import-Csv
; you could convert them back to CSV via ConvertTo-Csv
(in memory) or save them back to a file with Export-Csv
.