Powershell partial identical values two csv files

Hi,

I have two quite large csv files that contain values like this:

File one:
000074-e8ec29,33
00c0af-012651,28

file two:
000074 Amsterdam,On
00C0AF Berlin,Add

Is there a way that I can make powershell compare the first six digits of file one and two an than combine those in a new file, so it give me:

000074-e8ec29,33,000074 Amsterdam,On
00c0af-012651,28,00C0AF Berlin,Add

Thanks in advance !!
LVL 2
LoyallAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
Not directly.
But you can use pretty much any programming language (including powershell) to:
- read the first file line by line
- for each line search in the second file for a line starting with the first 8 characters of the current line
- if found, add it to the current line and write it to another file

If no one shows with a script by tonight I'll write one.

HTH,
Dan
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Does "quite large" mean that we cannot cache at least one of them in memory? If we can't, a slow, filesystem based merge have to be done.
0
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
Surely you can just first divide them into 2 parts with Data "-" this can now in 2 sheets be used to do Vlookup

- Rancy
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
Excel with your exaamples above

- Rancy
EE.xlsx
0
LoyallAuthor Commented:
Hi,

I,m sorry for my delayed response. Personal issues took control.
Dan, is your offer to write a script still valid ?

Kind regards,
Loyall
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Loyall,

please answer my question in http:#a41238506, so we can suggest a best-effort script (slow and file based versus fast and memory based).
0
LoyallAuthor Commented:
Hi Qlemo,

The files can be cached in memory.

Kind regards,
Loyall
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
$fileOne = 'C:\Temp\FileOne.csv'
$fileTwo = 'C:\Temp\FileTwo.csv'
$result  = 'C:\Temp\MergedFile.csv'

$hashFTwo = @{}
Import-Csv $fileTwo -Header ID, Text -Delimiter ' ' | % { $hashFTwo += @{$_.ID = $_.Text } }
Import-CSV $fileOne -Header id, text -Delimiter '-' |
% {
  $_.ID +'-'+ $_.Text + ',' + $_.ID +  ' ' + $hashFTwo[$_.ID]
} | Out-File -Encoding ASCII MergedFile.csv

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LoyallAuthor Commented:
Thank you very much Qlemo !!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.