Solved

Searching part of a file

Posted on 1997-05-23
1
134 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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

10 Experts available now in Live!

Get 1:1 Help Now