As you know sed is the one of the widely used stream editor to perform basic text transformations on an input stream (a file or input from a pipeline).
Most of the times I will use sed to process text file.
Recently I struggled couple of hours with sed when trying to replace a pattern with regular expression.
At last I got to know there is some issue with regex in sed.
Sed won’t support recent versions of regular expressions, so it not performed as I expected.
Then I tried with perl, since I got to know perl supports recent version of regular expressions.
I will show couple of example how to write perl one-liners.
$ echo ab | perl -p -e "s/a//g"
- Output: b
perl -p -e "s/a//g" <inputFile>
- you can use any input file with perl
Perl will support most of the functionality’s that are supported by sed, especially it support recent version of regular expression.
So try to avoid sed when you are using regular expressions instead use perl.