find string in a text file

  • Follow


hi guys,

First thanks for the support in my last question posted here.

Now i have been trying today to read about finding a way to solve this
(simple?) problem....which is...i have a string lets say "Leila" from
user and i want to search a text file with a table of values "name of
girl" "hair color", so like this somehow:


Leila black
Sabrina blonde
Sheila black
..
..
etc...

Now i want to get the value of the "hair color" and do something with
it....printf-it or whatever...what is the most memory effective way to
do so?is it with awk and grep and stuff? or something else?

Thanks


PS: the question is more about IP adresses, but maybe girls and would
get thoughts more smooth :-D
0
Reply kifah (10) 1/21/2004 5:53:00 PM

"Kifah Abbad" <kifah@web.de> wrote in message
news:a14d9cc.0401210952.54f5960f@posting.google.com...
> hi guys,
>
> First thanks for the support in my last question posted here.
>
> Now i have been trying today to read about finding a way to solve this
> (simple?) problem....which is...i have a string lets say "Leila" from
> user and i want to search a text file with a table of values "name of
> girl" "hair color", so like this somehow:

Could this be any more blatantly a homework question?

Tom


0
Reply tomstdenis3 (162) 1/21/2004 5:56:51 PM


Kifah Abbad wrote:
> hi guys,
> 
> First thanks for the support in my last question posted here.
> 
> Now i have been trying today to read about finding a way to solve this
> (simple?) problem....which is...i have a string lets say "Leila" from
> user and i want to search a text file with a table of values "name of
> girl" "hair color", so like this somehow:
> 
> 
> Leila black
> Sabrina blonde
> Sheila black
> .
> .
> etc...
> 
> Now i want to get the value of the "hair color" and do something with
> it....printf-it or whatever...what is the most memory effective way to
> do so?is it with awk and grep and stuff? or something else?
> 
> Thanks
> 
> 
> PS: the question is more about IP adresses, but maybe girls and would
> get thoughts more smooth :-D

If this file contains records (lines) of fixed length, you could
just position to a new record, read it in and process it.

For files containing variable length records, such as text files,
you will have to read in one record at a time.  You will need to
determine what is in a record and how to separate fields within
the record.

The fundamental process is to read in a record and compare the
key field with a given key.  If the keys match, process the
record; done.  Otherwise read in the next record; repeat.


-- 
Thomas Matthews

C++ newsgroup welcome message:
          http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq:   http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
          http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
     http://www.josuttis.com  -- C++ STL Library book

0
Reply Thomas_MatthewsSpitsOnSpamBots (631) 1/21/2004 7:49:54 PM

Kifah Abbad writes:

> Now i have been trying today to read about finding a way to solve this
> (simple?) problem....which is...i have a string lets say "Leila" from
> user and i want to search a text file with a table of values "name of
> girl" "hair color", so like this somehow:
>
>
> Leila black
> Sabrina blonde
> Sheila black
> .
> .
> etc...
>
> Now i want to get the value of the "hair color" and do something with
> it....printf-it or whatever...what is the most memory effective way to
> do so?is it with awk and grep and stuff? or something else?

There are several functions for dealing with strings in <string.h>.  I don't
really know what you are trying to do but that might well be a sufficient
clue.


0
Reply r124c4u1022 (2251) 1/21/2004 8:13:36 PM

Tom St Denis <tomstdenis@iahu.ca> scribbled the following:
> "Kifah Abbad" <kifah@web.de> wrote in message
> news:a14d9cc.0401210952.54f5960f@posting.google.com...
>> hi guys,
>>
>> First thanks for the support in my last question posted here.
>>
>> Now i have been trying today to read about finding a way to solve this
>> (simple?) problem....which is...i have a string lets say "Leila" from
>> user and i want to search a text file with a table of values "name of
>> girl" "hair color", so like this somehow:

> Could this be any more blatantly a homework question?

Yes, actually. I've seen a few that were obviously directly copied from
the homework assignments, without even bothering to add "I've been
trying" or an equivalent phrase.

-- 
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"No, Maggie, not Aztec, Olmec! Ol-mec!"
   - Lisa Simpson
0
Reply palaste (2323) 1/22/2004 9:14:56 AM

Kifah Abbad <kifah@web.de> wrote:
> do so?is it with awk and grep and stuff? or something else?
> 

This last sentence/question makes me think that you actually 
don't want to ask this question in clc. You probably want to post this
into comp.unix.programmer or some similar newsgroup.


-- 
Z (Zoran.Cutura@daimlerchrysler.com)
"LISP  is worth learning for  the profound enlightenment  experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days."   -- Eric S. Raymond 
0
Reply zoran.cutura (60) 1/22/2004 10:51:26 AM

On 21 Jan 2004 09:53:00 -0800, kifah@web.de (Kifah Abbad) wrote:

>Now i have been trying today to read about finding a way to solve this
>(simple?) problem....which is...i have a string lets say "Leila" from
>user and i want to search a text file with a table of values "name of
>girl" "hair color", so like this somehow:
>
>Leila black
>Sabrina blonde
>Sheila black
>.
>Now i want to get the value of the "hair color" and do something with
>it....printf-it or whatever...what is the most memory effective way to

Offhand, I'd say work directly from the file, accessing each record
sequentially.  Since your total database access is minimal, it really
doesn't pay to complicate the I/O more than this.

Where in your code are you having difficulty?  Post your code and indicate
precisely what your problem is.

-- 
Robert B. Clark (email ROT13'ed)
Visit ClarkWehyr Enterprises On-Line at http://www.3clarks.com/ClarkWehyr/
0
Reply Robert 1/22/2004 2:22:50 PM

6 Replies
46 Views

(page loaded in 0.336 seconds)

Similiar Articles:













7/12/2012 3:29:59 PM


Reply: