searching files
William Park
opengeometry at NOSPAM.yahoo.ca
Sat May 11 15:21:04 EDT 2002
zweistein <zweistein at net.hr> wrote:
> "Chris Liechti" <cliechti at gmx.net> wrote in message
> news:Xns920BB71141B16cliechtigmxnet at 62.2.16.82...
>> please provide more information about your data structure and what exactly
>> you want to search (names, numbers etc) and you will get more useful
>> feedback from this group.
>
> Well, I am storing every entry in a file. It stores only the name and the
> telephone number, and is tab delimited (name surname [TAB] tel.). I am
> trying to write a function to which a searchstring would be passed which
> would look into the entire file and show the entry that matches.
> I would like it to search both names and tel. numbers.
This is no-brainer in Unix, ie.
egrep 'surname' file
awk '/surname/ {print}' file
In pure Python, you have to read the file into list, and do string/re search.
--
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin
More information about the Python-list
mailing list