Solved

Searching part of a file

Posted on 1997-05-23
1
141 Views
Last Modified: 2013-12-25
I was wondering if anyone knows where i could
find a script, or knows the procedure that would allow
me to search parts of *one* file for string. I.e. We have a list of names with an email address and would like to be able to have an engine search inside the file for the names instead of searching for a file with the names.. Thanks in advance :)
0
Comment
Question by:Primetyme
1 Comment
 
LVL 5

Accepted Solution

by:
icd earned 100 total points
ID: 1828086
Assuming your file is of the form

email@somewhere.com,fred bloggs

then you can search it with a perl script similar to:-

open (FID, "filename.txt");
while (<FID>) {
  chop;
  ($email, $name) = split(/,/, $_);
  if ($name eq $theNameIAmLookingFor) {
    print "The email you want is $email\n";
  }
}
close(FID);

Alternatively if it is a Unix host you could use a grep program.

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now