On Wed, Jul 14, 2010 at 10:43 PM, fd <[email protected]> wrote: > If I introduce the -o option so that I have only the part of each line > that matches a pattern I have no result > > gcc --help | grep -P -o '(?<=the )' > > Is this a bug, or am I doing something wrong.
You have an assertion pattern but are missing the match pattern (actually, you have a 0-length match, much like you would with a ^ or $ anchor.). Add the --color=always option to grep to visualize this. For example, contrast this: $ echo "this is the beginning of time" | grep --color=always -P '(?<=the )' this is the beginning of time ... with this: $ echo "this is the beginning of time" | grep --color=always -P '(?<=the ).*' this is the beginning of time By adding the .* match pattern "beginning of time" becomes colored. It's the colored part that grep shows with the -o option. $ echo "this is the beginning of time" | grep --color=always -o -P '(?<=the ).*' beginning of time Good luck and let us know how things go. Regards, - Robert -- You received this message because you are subscribed to the Linux Users Group. To post a message, send email to [email protected] To unsubscribe, send email to [email protected] For more options, visit our group at http://groups.google.com/group/linuxusersgroup
