Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi,
i want to find matched cases in my phonelist.txt file, and then save the results in an array so i can process them.
for example, the phonelist.txt file consists of different fields separated by semicolons as:
jon;555-5555;jon@hotmail.com
kathy;444-4444;kathy@hotmail.com
mark;333-3333;mark@hotmail.com
jon;111-1111;jon@hotmail.comhow do i conduct a search by name, by phone number, or by email address and then store the matched cases in an array?
if i search for jon, then i should get two results, and i want to process these two results.
thanks,
jason

i need to clarify something:
after the search, i want to save the entire record (that contains name, phone #, email address) of each result. for example, if i search for jon, then i should get two records of jon. then i can process each record accordingly.
thanks,
jason

You don't specify a language preference, so I'm going to pick the easiest for the task described. But depending on exactly what you want to do, there may be better answers.
grep is a shell script command for search files for specified text.
> grep jon phonelist.txt
jon;555-5555;jon@hotmail.com
jon;111-1111;jon@hotmail.com
The command above searches for the string 'jon' in the file 'phonelist.txt'. Any lines containing 'jon', anywere in the line, are output.That's a pretty simple answer, but it answers the question that you asked.

Hi Jason,
I suggest you use Awk. It's the best, when the no of records involved are more. Grep has a limitation as it does scan the whole file once for each string you search.Awk is powerful in a way that it works line by line.
So, in you case if you had to use awk it would be like this:
awk -F";" '$1=="The name you want"{print $0}' phonelist.txt
Thereafter you could put conditions like AND , OR along with conditional statments of $1 above and get the required result.
For storing in an array it's as simple as you do in C language.
So go ahead anf start scripting :)
~deeps

![]() |
store a line from file in...
|
multiple IP
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |