Reading sub-string from a file

Chris Angelico rosuav at gmail.com
Thu Feb 16 05:32:10 EST 2012


On Thu, Feb 16, 2012 at 8:52 PM, Smiley 4321 <ssmile03 at gmail.com> wrote:
> int Jockey_Apple_cat_1KK(float, int, char, int);
> int Jockey_Apple_cat_look(int, float, int, int);
> int Jockey_Apple_cat_test_ki21es(int, int, int, int);
> int Jockey_Apple_cat_tarLK12OU(void, int, int, int);
> ---
>
> Here substring "Jockey_Apple_cat" is common from 3rd line onwards as a
> function name. I wish to extract ONLY that function name which has
> 'Jockey_Apple_cat' as a substring and ignore remaining function names.

Try this:

grep -o 'Jockey_Apple_cat[^(]*' test.conf

It's not Python, but it might serve you better than knocking something
together! But if you're using this to learn Python, Peter Otten's
solution is, I think, what you want.

ChrisA



More information about the Python-list mailing list