Thread: grep

  1. #1
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065

    grep

    When doing command line thingys, sed allows one to do really cool stuff like:

    Long way:
    sed 's/^something/something else/' | sed 's/^morestuff$/othermorestuff/'

    Short way:
    sed -e 's/^something/something else/' -e 's/morestuff$/othermorestuff/'

    The Short way speeds up multiple changes by eliminating the pipe (which creates natural overhead).

    So, now having said this, is there a way to do this with grep?

    For example, what I would like to do is (in the Linux kernel code):

    grep --color -rI kmalloc . | grep -v return | grep -v '=[<space><tab>]*kmalloc' . . .

    but in one line.

    Any ideas?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    No way to do this in grep to my knowledge, except by enclosing the inner grep in "quotes and backticks" and as long as the outer grep only returns one result.

    Code:
    grep -e "`grep args`" args
    Because of the way quotes and backticks are handled, it's possible this doesn't work outside bash. It's also impossible to my knowledge to enclose a third grep.

    EDIT: changed "inner" to "outer" grep on the first line. The inner grep can return more than one result, of course (just tested it in any case). It's the outer grep that can't. Only the first result will be handled.
    Last edited by Mario F.; 01-12-2011 at 07:45 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Yeah, I already "knew" that, but I was hoping I had missed something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. programming with grep
    By George2 in forum Tech Board
    Replies: 4
    Last Post: 11-18-2006, 03:30 AM
  2. simple grep problem
    By cdave in forum Windows Programming
    Replies: 7
    Last Post: 12-29-2005, 05:48 PM
  3. Grep Last Pattern Output
    By cfriend in forum Linux Programming
    Replies: 1
    Last Post: 09-18-2004, 10:14 AM
  4. Grep
    By cfriend in forum Linux Programming
    Replies: 3
    Last Post: 09-17-2004, 05:34 AM
  5. grep
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-26-2002, 12:11 PM