find string in a text file

K

Kifah Abbad

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
 
T

Tom St Denis

Kifah Abbad said:
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
 
T

Thomas Matthews

Kifah said:
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
 
O

osmium

Kifah said:
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.
 
J

Joona I Palaste

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.
 
Z

Zoran Cutura

Kifah Abbad said:
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.
 
R

Robert B. Clark

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,137
Messages
2,570,797
Members
47,342
Latest member
eixataze

Latest Threads

Top