tags:

views:

69

answers:

2

Is there a difference in regular expressions on Linux and on HPUX?

I am using them in sed.

I am trying the following which works only on Linux:

sed -e "s/^\s*ant\s*$/#ant/g" Makefile

Now I see that if I remove the '^' then it works on HP too. As far as I understand, this should be supported by both.

+1  A: 

Where are you using them? In sed? In some scripting language (say, perl)? Somewhere else? The question is unclear. You have to post your actual regex, or better, example script/input/output. Anyway, \s, I guess, stands for `whitespace' and that is determined by locale and, maybe, other factors.

shylent
yes, using sed.
Your input please? And the actual regex? Anyway, it is most likely a locale thing. You could try using [:space:] instead of \s too.
shylent
A: 

The short answer is "yes, there probably is a difference".

The long answer :

It depends on what version of sed you are using on each machine, not what operating system the machine is running.

In my experience I've found that the toolkit (i.e. sed, grep, awk, etc) installed on the likes of HP-UX is often inferior to the versions found on most popular Linux distributions.

My guess is that on HP-UX you are using a version of sed built by HP and you are using GNU sed on Linux. You'll either need to read up on what the HP version can or cannot do and find the common ground with your version on Linux, or see if you can get the GNU version installed somewhere on your HP machine.

As for the specific regexp you give, well as with any regexp problem it would help if you also gave some example text to match against and stated what you are expecting the regexp to accomplish.

Tim