C Board  

Go Back   C Board > Community Boards > Tech Board

Reply
 
LinkBack Thread Tools Display Modes
Old 11-17-2006, 04:55 AM   #1
Registered User
 
Join Date: May 2006
Posts: 1,579
programming with grep

Hello everyone,


I am programming with grep command in my C/C++ application to steal its string manipulation functions. :-)

I have completed several simple cases. I am meeting issues with two cases, and I am wondering how to represent it in grep.

1. find the lines contain "foo" or "goo";
2. find the lines contain "foo" but no "goo".

could anyone help please?


thanks in advance,
George
George2 is offline   Reply With Quote
Old 11-17-2006, 06:32 AM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,640
> I am programming with grep command in my C/C++ application to steal its string manipulation functions. :-)
Ugh!

Try using the regexp library which presents the same functionality as grep but without all the expensive overhead of spawning a separate process every time you want to do something.

> 1. find the lines contain "foo" or "goo";
egrep '[fg]oo'
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 11-17-2006, 06:49 AM   #3
Registered User
 
Join Date: May 2006
Posts: 1,579
Thank you Salem!


Quote:
Originally Posted by Salem
> 1. find the lines contain "foo" or "goo";
egrep '[fg]oo'
Your method does not work in this case. How to find the string contains either "abc" or "def"? Any general ways to implement or logics?


regards,
George
George2 is offline   Reply With Quote
Old 11-17-2006, 06:54 AM   #4
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,640
Code:
egrep 'read|the|manual' file.txt
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 11-18-2006, 03:30 AM   #5
Registered User
 
Join Date: May 2006
Posts: 1,579
Cool Salem, thank you!


Quote:
Originally Posted by Salem
Code:
egrep 'read|the|manual' file.txt

regards,
George
George2 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple grep problem cdave Windows Programming 7 12-29-2005 05:48 PM
Grep Last Pattern Output cfriend Linux Programming 1 09-18-2004 10:14 AM
Grep cfriend Linux Programming 3 09-17-2004 05:34 AM
Grep Adam C Programming 0 06-07-2002 06:06 AM
grep Unregistered C Programming 3 02-26-2002 12:11 PM


All times are GMT -6. The time now is 09:57 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22