[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep bug with -P -o option
From: |
Davide Brini |
Subject: |
Re: grep bug with -P -o option |
Date: |
Thu, 15 Jul 2010 09:13:57 +0100 |
User-agent: |
KMail/1.13.3 (Linux/2.6.32-gentoo-r10; KDE/4.4.4; x86_64; ; ) |
On Thursday 15 Jul 2010 03:43:31 fd wrote:
> Dear all
>
> I'm a novice in this Linux business, but I think there's something not
> right. When I try to search using a perl regular expression, so if a
> do:
>
> gcc --help | grep -P '(?<=the )'
>
> I get all lines for which there is any text preceded by "the "
>
>
> -dumpspecs Display all of the built in spec strings
> -dumpversion Display the version of the compiler
> -dumpmachine Display the compiler's target processor
> -print-search-dirs Display the directories in the compiler's
> search path
> -print-libgcc-file-name Display the name of the compiler's
> companion library
> -print-file-name=<lib> Display the full path to library <lib>
> -print-prog-name=<prog> Display the full path to compiler component
> <prog>
> -print-multi-directory Display the root directory for versions of
> libgcc
> -print-multi-lib Display the mapping between command line
> options and
> ...
>
> 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.
The lookbehind is a zero-width assertion. Think of it as a boolean condition.
If you want the text that follows the (first) "the ", then do
grep -P -o '(?<=the ).*'
--
D.