I am happy that
grep does support Perl Compatible Regular Expressions with the
Is there a reason why the tool
sed does not have this feature?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
You can use the Pathological Eclectic Rubbish Lister:
perl -pe 's/../../g' file
or inline replace:
perl -pie 's/../../g' file
This works for the cases where I use
sed. If things get more complicated I write a small python script.
BTW, I switched to No Shell-Scripting
In the case of GNU Sed, the stated reason appears to be
I was afraid it fell into one of those 'cracks'...though from what was said at the time, some part of the work was already done and it looked like a matter of docs and packaging... (though, I admit, in Computer Sci, the last 10% of the work often takes 90% of the time...
See GNU bug report logs - #22801 status on committed change: upgrading 'sed' RE's to include perlRE syntax - or search the sed-devel Archives for "PCRE" if you want more details.
Don't forget you can use
perl itself for many of the simple one-liners for which you might want to use PCRE in
Personally I found it easier to do in Python than Perl or Sed.
cat file \ | python3 -c 'import sys, re; s = sys.stdin.read(); s=re.sub(r"regex", "replace string", s); print(s);' \ | sudo tee file
# add quay and docker registries to approved cri-o registries cat /etc/crio/crio.conf \ | python3 -c 'import sys, re; s = sys.stdin.read(); s=re.sub(r"#registries\s+\=\s+\[\n#\s+\]", "registries = [\"docker.io\",\"quay.io\"]", s); print(s);' \ | sudo tee /etc/crio/crio.conf