1826489 Members
4233 Online
109692 Solutions
New Discussion

Regex tips

 
SOLVED
Go to solution
2xyo
Frequent Advisor

Regex tips

Dear,

I have this regular expression wich works fine on linux with sed 4.1.5 :

# echo "bla: 567/1234" | sed -n -e "s_.*\s\([0-9]*\)/\([0-9][0-9][0-9][0-9]\).*_\1_p"
567

Now, i try this on HP-UX 11iv1 but it return nothing...
I also try with :
echo "bla: 567/1234" | sed -n -e "s_.*\[:space:]\([0-9]*\)/\([0-9][0-9][0-9][0-9]\).*_\1_p"

i suspect \s doesn't work with this version of sed (sed --version doesn't works on HP..)

Any help would be appreciate
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: Regex tips

Hi:

First, HP's 'sed' lacks the power of the GNU 'sed'. Even things like '\s' for whitespace are missing.

In lieu of using:

\s*

...you can use:

[[:space:]]*

Notice the double brackets where you only used single ones.

Hence, this works on HP-UX:

# echo "bla: 567/1234" | sed -n -e "s_.*[[:space:]]\([0-9]*\)/\([0-9][0-9][0-9][0-9]\).*_\1_p"
567

Regards!

...JRF...
2xyo
Frequent Advisor

Re: Regex tips

Thanks

It's works (forget double bracket..) :
echo "bla: 567/1234" | sed -n -e "s_.*[[:space:]]\([0-9]*\)/\([0-9]*\).*_\1_p"