Use one file for input and search a second file

rated by 0 users
This post has 5 Replies | 2 Followers

Not Ranked
Posts 2
UriahHeep Posted: 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

Top 50 Contributor
Posts 80

show sample files.

Top 50 Contributor
Posts 80

$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
Posts 80

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

Not Ranked
Posts 2

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

Have a great weekend!

Top 10 Contributor
Posts 658
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.