Use one file for input and search a second file

rated by 0 users
Not Answered This post has 0 verified answers | 5 Replies | 2 Followers

Not Ranked
2 Posts
UriahHeep posted on 02-03-2012 10:29 AM

I have 2 files:  One contains email addresses, and the second contains email addresses, as well as additional text in each line containing the email addresses. 

I am trying to use the first file (list of email addresses) as an array input to search the second file and return each line containing the addresses from the first file ( need the additional info that is in each line that contains an email address from the first file).

I'm pulling my hair out here!

 

Thanks,

UriahHeep

All Replies

Top 50 Contributor
80 Posts

show sample files.

Top 50 Contributor
80 Posts

$emailsList = get-content .\emails.txt

$targetFile = get-content .\garbage.txt

$rowIndex=0

foreach ($row in $targetFile){

++$rowIndex

foreach ($email in $emailsList){

if ($row.tolower().contains($email.trim().tolower())){

"Row $rowIndex`: $row"

}

}

}

Top 50 Contributor
80 Posts

How correctly to format a code at a forum? Why at me it so awfully looks?

Not Ranked
2 Posts

Many thanks Bush!  This worked perfectly, and I learned a new trick!

Have a great weekend!

Top 10 Contributor
658 Posts
Idera Employee

One option is to use an Editor that can format your code as HTML (PowerShellPlus can do this for you). And then use the HTML button on the toolbar above to insert the HTML proper.

Page 1 of 1 (6 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.