programming with grep

This is a discussion on programming with grep within the Tech Board forums, part of the Community Boards category; Hello everyone, I am programming with grep command in my C/C++ application to steal its string manipulation functions. :-) I ...

  1. #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

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > 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.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #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

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple grep problem
    By cdave in forum Windows Programming
    Replies: 7
    Last Post: 12-29-2005, 04:48 PM
  2. Grep Last Pattern Output
    By cfriend in forum Linux Programming
    Replies: 1
    Last Post: 09-18-2004, 10:14 AM
  3. Grep
    By cfriend in forum Linux Programming
    Replies: 3
    Last Post: 09-17-2004, 05:34 AM
  4. Grep
    By Adam in forum C Programming
    Replies: 0
    Last Post: 06-07-2002, 06:06 AM
  5. grep
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-26-2002, 11:11 AM

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