Compatible awk command

the following command works beautifully. it basically grabs the content of a file from First to End, then excludes any lines containing specific patterns.

awk '/^First/,/^End$/ {if (!/#\/bin\/sh|not.*commonly|#/) print}'  datafile.

i never had any issues with the command until I ran it on a Ubuntu box 13.04. when i ran it against a datafile, I got back no response. Nothing was outputted to the screen. It wasnt until I installed gawk on the system that the command started to work.

can anyone help me rewrite this command to make it more portable with default versions of awk? i dont want to have to install gawk. this script will be run on a a client machine and they dont like having to install anything on their system because they fear it'll break something else.

try this - some awk-s are finicky...:

awk '/^First/,/^End$/ {if ((!/#\/bin\/sh)|(not.*commonly/)|(/#/)) print}'  datafile.

ubuntu uses mawk by default, which is faster but finicky.

awk '/^First/,/^End$/ {if (!/#\/bin\/sh|not.*commonly|#/) print}' file 

is equivalent to:

awk '/^First/,/^End$/ {if (!/not.*commonly|#/) print}' file

I do not see how mawk or any awk would have a problem with that...

Could you post a sample where it goes wrong?

--

This would have a different meaning and the syntax is incorrect..

it doesnt look like awk is going to be reliable here. but sed seems to be.

i found this command online:

sed -n '/ABC/,/^[^+]/{x;/^$/!p;}' file

and i modified it to look like this:

sed -n '/^First/,/^End$/ {x ; /#\/bin\/sh|not.*commonly|#/!p;}'

which seems to work. but dont know if im reading the command correctly. i take it, im storing everything between and including lines from "First" to "End" to variable x. then, im only printing lines from variable x which do not contain the strings

#\/bin\/sh|not.*commonly|#

/#something|#/ is equal to /#/

awk '/^First/,/^End$/ {if (!/not.*commonly|#/) print}' datafile

The same with Unix sed (as always: multi-line works around bugs)

sed -n '
/^First/,/^End$/{
  /not.*commonly/b
  /#/b
  p
}
' datafile