473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

find string in a text file

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
Nov 14 '05 #1
6 10087

"Kifah Abbad" <ki***@web.de> wrote in message
news:a1*************************@posting.google.co m...
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
Nov 14 '05 #2
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.
Nov 14 '05 #3
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

Nov 14 '05 #4
Tom St Denis <to********@iahu.ca> scribbled the following:
"Kifah Abbad" <ki***@web.de> wrote in message
news:a1*************************@posting.google.co m...
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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"No, Maggie, not Aztec, Olmec! Ol-mec!"
- Lisa Simpson
Nov 14 '05 #5
Kifah Abbad <ki***@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 (Zo**********@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
Nov 14 '05 #6
On 21 Jan 2004 09:53:00 -0800, ki***@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/
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: kittykat | last post by:
Hi, I was wondering if you could help me. I am writing a program in C++, and the problem is, i have very limited experience in this language. I would like my user to enter a specific pattern, and...
10
by: mjl1976 | last post by:
I have textBox1 which is the string i want to search in file.txt Button1 I want textBox2 to show the line of text i am searching when i click button1
7
by: Yongsub Eric Shin | last post by:
Hi. I'm just a beginner in ASP.Net. I started writing codes and I keep on getting this Runtime Error page, where it says "Description: An application error occurred on the server. The current...
2
by: Bryan_Cockrell | last post by:
Hi World, I am extracting text from an ebcdic header using dd in the cygwin environment (bash/ksh) as below in order to rename the file to something intelligent. I'm using a specific string...
3
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it...
22
by: Steve Richter | last post by:
Does the .NET framework provide a class which will find the item in the collection with a key which is closest ( greater than or equal, less than or equal ) to the keys of the collection? ex:...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i...
1
by: xetulul | last post by:
my problem is that im unable to match a user input word to a word in a string. the strings are in a file and then placed in nodes. i have to go through each token in each node to find the 'word'....
9
by: WebArchitect | last post by:
I have a text file. My text file contains lines with double quotes around it. I trying to code if a line has double quotes around it Then make it bold My code is below and it is not working....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.