On OSX, the system sed seems, at times, a bit limited regarding regular expressions and some escape characters — so much, that I end up using perl -pe a fair bit of the time, and now I’m wondering if I should care about using sed at all.
I usually need this when piping a lot of commands in a row, usually calling sed and perl multiple times during its execution, and I’d like to know if I should use sed when it does the job, using perl only when it is necessary. I’m interested in this from a performance point of view (having multiple commands of this kind in a script can make a difference in the end), but if there are any other considerations you deem worthy of mentioning, they’re welcome, naturally.
Perl is probably a bit slower than sed (but not by much — it is a very fast scripting language); however, if Perl does what you need and sed doesn't, use Perl.
Note that Perl is (still) distributed with the programs s2p and a2p which convert sed and awk scripts respectively into Perl. So you can devise your script in sed and then automatically translate to Perl (and adapt to exploit enhanced Perl regular expressions, etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With