Search code examples
perlawksolarispcrenawk

grep regex to perl or awk


I have been using Linux env and recently migrated to solaris. Unfortunately one of my bash scripts requires the use of grep with the P switch [ pcre support ] .As Solaris doesnt support the pcre option for grep , I am obliged to find another solution to the problem.And pcregrep seems to have an obvious loop bug and sed -r option is unsupported ! I hope that using perl or nawk will solve the problem on solaris.

I have not yet used perl in my script and am unware neither of its syntax nor the flags.

Since it is pcre , I beleive that a perl scripter can help me out in a matter of minutes. They should match over multiple lines .

Which one would be a better solution in terms of efficiency the awk or the perl solution ?

Thanks for the replies .


Solution

  • These are some grep to perl conversions you might need:

    grep -P PATTERN FILE(s) ---> perl -nle 'print if m/PATTERN/' FILE(s)

    grep -Po PATTERN FILE(s) ---> perl -nle 'print "$1\n" while m/(PATTERN)/g' FILE(s)

    That's my guess as to what you're looking for, if grep -P is out of the question.