0

I prefer (Perl/Python Compatible Regular Expressions) regular expressions.

man grep:

...., but only work if pcre is available in the system

Is this supported on the most common linux distributions?

I don't care for freebsd, solarix, busybox, ...

  • short answer: yes. (and is 3 times faster then the default) – JJoao Mar 5 '15 at 9:02
  • 1
    Why don't you use ack? – cuonglm Mar 5 '15 at 9:31
  • A second endorsement for ack. ack is written in Perl itself, so you get the full Perl regular expression set, plus you can customize the output using capture groups, as in ack '#include <(.+)>' --output='$1'. (Note: I wrote ack.) – Andy Lester Mar 5 '15 at 16:02
4

PCRE is installed on pretty much all server and desktop Linux systems, but you can't necessarily expect it on lightweight systems or embedded systems (phones, routers, TVs, and other IoT), as they often have very trimmed versions of the standard userland (basically, anything with a busybox base is all but guaranteed to lack PCRE).

Debian has a Popularity Contest feature that measures installation metrics on various packages. grep (25th most common, 176k installs) depends (not optionally) on libpcre3 (94th most common, 174k installs). I cannot explain the discrepancy, but I also wouldn't worry about it.

It should be safe to assume that modern desktop and servers running full Linux distributions will have versions of grep compiled with PCRE support.

Still, if you want PCRE with a better assurance of portability, don't rely on grep -P or pcregrep (9363th at 1k installs) or ack (21728th at 180 installs), use perl (88th at 175k installs) directly:

perl -ne 'print if /regexp/'

Note, there are servers that intentionally lack perl, python, and php for "security purposes," namely that many rogue scripts (e.g. rootkits) depend on these and therefore cannot run. This is very rare (and kind of silly since there are plenty of potent rogue POSIX shell scripts).

Note 2: Perl is slow (as is python). LibPCRE is much faster, but the simpler your regexps, the better performance you'll get. If possible, use grep alone (BRE, basic regexps) or else try grep -E (ERE, extended regexps) rather than diving deeper into PCRE land.

  • 1
    I just wanted to point out that with the push of Docker being bigger and bigger in 2015 it's no longer safe to assume such a thing, Ubuntu is popular (the most popular) for Docker but Alpine Linux (a busybox based distro) is becoming popular. – Jordon Bedwell Aug 18 '15 at 4:12
  • Alpine's Wikipedia article notes it "is primarily designed for x86 routers, firewalls, VPNs, VoIP and servers," so I wouldn't call it a desktop distro. That said, I did include servers ... but DistroWatch's popularity rankings do not rank Alpine in its top 50 distros, so I stand by my statement. – Adam Katz Aug 18 '15 at 4:27
  • Do you have popularity metrics of Linux distros hat run Docker (which would make it more of an appliance than a general server)? Or did you mean that run within Docker? I can't find either, nor any other evidence to back your claim. Even if such a ranking does exist, Alpine won't be in the top five, and as the only distro lacking grep+libpcre, it would be a corner case. There are exceptions to every rule. – Adam Katz Aug 18 '15 at 16:57
0

As far as I remember, I've seen pcre on a lot of Linux distributions such as CentOS, Ubuntu, RedHat, Debian and other distribution based on these. and I think it won't make you any problems. also the source is available:

http://sourceforge.net/projects/pcre/files/pcre/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.