Perl Regex with unix grep command
Perl Regex with unix grep command
am 03.09.2011 23:01:39 von Jon Forsyth
--20cf305b0856c7b48704ac0fc81c
Content-Type: text/plain; charset=ISO-8859-1
Hello,
According to the grep manual page I can use the -P option to use Perl
regular expressions as follows:
grep -P PERL_REGEX INPUT_FILE
however, I cannot get the following pattern to match a literal dollar sign:
grep -P makan\$ file.txt
when I know this pattern is in the file. It matches the shorter string
without the dollar sign if I leave \$ out.
Thanks,
Jon
--20cf305b0856c7b48704ac0fc81c--
Re: Perl Regex with unix grep command
am 03.09.2011 23:15:51 von Shawn H Corey
On 11-09-03 05:01 PM, Jon Forsyth wrote:
> Hello,
>
> According to the grep manual page I can use the -P option to use Perl
> regular expressions as follows:
>
> grep -P PERL_REGEX INPUT_FILE
>
> however, I cannot get the following pattern to match a literal dollar sign:
>
> grep -P makan\$ file.txt
# You have to get the backslash past the shell
grep -P 'makan\$' file.txt
# or
grep -P makan\\$ file.txt
>
> when I know this pattern is in the file. It matches the shorter string
> without the dollar sign if I leave \$ out.
>
> Thanks,
>
> Jon
>
--
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
"Make something worthwhile." -- Dear Hunter
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Perl Regex with unix grep command
am 03.09.2011 23:18:03 von Uri Guttman
>>>>> "JF" == Jon Forsyth writes:
JF> According to the grep manual page I can use the -P option to use
JF> Perl regular expressions as follows:
JF> grep -P PERL_REGEX INPUT_FILE
just to let you know, nothing but perl can run perl regexes. all the
ones that claim it are doing subsets and in some cases not even close
anymore.
JF> however, I cannot get the following pattern to match a literal
JF> dollar sign:
JF> grep -P makan\$ file.txt
you are escaping that from the shell but the 'perl' regex will then make
it match the end of a line or before a newline. you need to quote it
against the shell with '' and keep the \ in there.
uri
--
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
------------ Perl Developer Recruiting and Placement Services -------------
----- Perl Code Review, Architecture, Development, Training, Support -------
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Perl Regex with unix grep command
am 04.09.2011 08:35:03 von Shlomi Fish
Hi all,
On Sat, 03 Sep 2011 17:15:51 -0400
Shawn H Corey wrote:
> On 11-09-03 05:01 PM, Jon Forsyth wrote:
> > Hello,
> >
> > According to the grep manual page I can use the -P option to use Perl
> > regular expressions as follows:
> >
> > grep -P PERL_REGEX INPUT_FILE
> >
> > however, I cannot get the following pattern to match a literal dollar s=
ign:
> >
> > grep -P makan\$ file.txt
>=20
> # You have to get the backslash past the shell
>=20
> grep -P 'makan\$' file.txt
>=20
> # or
>=20
> grep -P makan\\$ file.txt
>=20
Just to be a bit more pedantic, in this case:
grep -P makan\\\$ file.txt=20
would be safer and more idiomatic, because otherwise the shell would treat =
the
string as a literal backslash followed by the opening of a shell variable,
which all start with "$".
Regards,
Shlomi Fish
--=20
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Best Introductory Programming Language - http://shlom.in/intro-lang
I might be mad. But Iâ=99m a mad genius.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/