Re: Regular expression with egrep question...
On Thu, 03 Jan 2008 22:31:38 -0500, somebody wrote:
> On Thu, 03 Jan 2008 18:31:39 -0600, Ed Morton wrote:
>
>> egrep '[[:blank:]]+' myfile.txt
>>
>> is probably what you want. "\s" may be a shorthand perl-ism which your egrep may
>> support when you use the "-P" (for perl) flag.
[...]
> I tried the -P switch specifying perl type regex, but get this error.
> Any ideas?
[...]
> michigan:/home/sombody> egrep -P '^\s+' test.txt
> egrep: conflicting matchers specified
egrep is a non-standard shortcut for "grep -E". -E selects
extended regexps, -P perl-compatible regexps, hence the
conflict.
Use grep -P.
Note that \s is [[:space:]], not [[:blank:]] so includes a
number of "space" characters that you may not want matched such
as form feed, vertical tab, carriage return...
[[:blank:]], [[:space:]] called charater class are standard
(POSIX). grep and -E are as well.
egrep is quite common but not POSIX. -P is a GNU extension and
is not available in every GNU grep as it requires the PCRE
library.
Note that the "+" is useless as any line that matches ^\s+ also
matches ^\s and vice versa.
perl -ne 'print if /^\s/'
would be more portable.
--
Stephane
|