0

I've lately been using pcregrep to do Perl-style group matching when doing my bash scripts.

The problem with pcregrep is that it's not readily available on Linux machines in general.

An alternative would be to run Perl one liners or maybe, if possible, Python one liners to do those matches.

I was wondering how good of an approach would this be? I don't know how fast both Perl and Python are initializing, as I can imagine that if my script has to consecutively make Regex matches and every time it needs to spawn a new instance of either Perl or Python, things can go slow fast. On the other hand, I don't feel like investing at the moment on learning the full languages, so I can do the whole script in them (Perl seems to be mostly a dead language, Python is the new king).

How do you guys deal with this (or similar?) situations?

closed as off-topic by gnat, Kilian Foth, TheCatWhisperer, amon, 8bittree Feb 6 '18 at 22:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to find or recommend tools, libraries, programming languages, resources (including books, blogs, tutorials, and examples), or projects to undertake are off-topic here as they attract opinionated answers that won't have lasting value to others. You may be able to get help in The Whiteboard, our chat room." – gnat, Kilian Foth, TheCatWhisperer, amon, 8bittree
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    I don't know how fast both Perl and Python are initializing... -- There's a way to find out. – Robert Harvey Jul 31 '16 at 0:14
  • Ok, stackoverflow.com/questions/12793562/…. My question is still the same. What are the real world alternatives people are using to avoid using pcregrep? – devoured elysium Jul 31 '16 at 0:23
  • 2
    perl -ne 'print if /regex/' is a quick+dirty grep using perl regex. Try yourself if the speed is enough for you. – Steffen Ullrich Jul 31 '16 at 5:39
  • 3
    "Perl seems to be mostly a dead language"... yeah right. As dead as Java and C++ I hazard. – Martin Ba Aug 2 '16 at 9:44
  • 4
    @devouredelysium - /me: chuckles. Even if I would take that index for anything, it's in the top ten FCS. About as popular as JavaScript, and like that is dead. – Martin Ba Aug 2 '16 at 19:13
6

Unless you work with some very arcane systems then if the remote system has bash, it will have Perl as well. A considerable amount of all the core utilities on almost all Linuxes are written in Perl after all.

If you want Perl functionality, write your stuff in Perl. It's available and gets the job done.

Whether you consider it to be a dead language1 or not doesn't make a difference for that decision. You can still use it if it's available and gets the job done. You want strong regular expressions and availability. It gives you both. You don't even need to learn a lot of syntax for the stuff you want to do. If you can solve it in bash, you can also easily do it in Perl.


1) I disagree strongly as Perl has successfully paid my rent for the last 10 years and continues to do so

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