2

Input:

tmp# cat test5
1234      012345
0.000             01234
01/02/03          5467
01234           0123
05554567       234
0099
0000           000054

Output on Bash Shell:

[tmp]# perl -lpe 's#(^|\h)\K0[^./\h]+(?=\h|$)#"$&"#g' test5
1234      "012345"
0.000             "01234"
01/02/03          5467
"01234"           "0123"
"05554567"       234
"0099"
"0000"           "000054"

Output on /sbin/sh shell on HP Unix:

/tmp # perl -lpe 's#(^|\h)\K0[^./\h]+(?=\h|$)#"$&"#g' test5
1234      012345
0.000             01234
01/02/03          5467
01234           0123
05554567       234
0099
0000           000054
  • 2
    The shell has nothing to do with it. What versions of Perl are you using on the two systems? – Kusalananda Nov 16 '17 at 9:43
  • perl on ubuntu is 5.22 (from 2015) while my perl on hp-ux is 5.8.8 (from 2006). You may need to compile it. – Archemar Nov 16 '17 at 9:58
  • I think this is the first time I have ever seen \h used rather than \s. (I had to look it up.) – roaima Nov 16 '17 at 10:16
0

It looks like you want to write a letter quote all integer values that begin with zero. This is a much simpler RE that achieves this aim:

perl -lpe '1 while (s/(^|\s)(0\d*)(\s|$)/$1"$2"$3/)' test5

1234      "012345"
0.000             "01234"
01/02/03          5467
"01234"           "0123"
"05554567"       234
"0099"
"0000"           "000054"
| improve this answer | |
0

The two machines are running different versions of Perl, and the difference in shells have nothing to do with it.

Perl on HP-UX is, according to Archemar, Perl 5.8.8, and the positive look-behind escape \K and the \h escape for horizontal whitespace were both added in Perl 5.10. This is why the two Perls give you different results.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.