Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Perl regex attributes in awk

Tags:

regex

awk

perl

pcre

If I use Perl regex (PCRE) with GNU grep, it works pretty well; please consider:

$ echo FOO | grep -P '(?i)foo'
FOO

I tried PCRE with awk but awk does not support PCRE.

I only found three different regex modifiers for awk/gawk

--posix
--traditional
--re-interval

Does any of the awk family use Perl regex (PCRE) like the grep -P example above?

like image 758
capser Avatar asked Dec 15 '22 15:12

capser


1 Answers

No, awk does not support Perl REs. One of the primary tenets of the awk language is to keep the language small by not providing constructs to do simple things a bit more briefly. That's how they avoid the language bloat and associated complexity that perl suffers from (see http://www.zoitz.com/archives/13 for the common perception of perl readability). In this case while some of the Perl RE syntax lets you do some things a bit briefer, you don't NEED special language constructs to do them as there's other ways to do whatever you want with existing constructs (maybe not in one RE or using one function so not as briefly) so awk doesn't support them.

like image 99
Ed Morton Avatar answered Jan 02 '23 03:01

Ed Morton