Page 1 of 1

sed on OS4 is buggy

Posted: Thu Aug 28, 2014 10:53 am
by Deniil
Hi

I have been struggling quite a bit with something that seemed simple enough (well, relative to sed that is). I want to extract the second "x:...." up to the next "x:..".

Have a look at this (run from sh):

Code: Select all

> echo "x:abc/def/x:ghi/jkl/x:mno/pqr" | sed 's/x:[a-z\/]*x:ghi\([^:]*\)\/x:.*/\1/'
x:abc/def/x:ghi/jkl/x:mno/pqr
(match (or print) failed)

> echo "x:abc/def/x:ghi/jkl/x:mno/pqr" | sed 's/x:[a-z\/]*x:ghi\([^:]*\)\/x:.*/\1 /'
/jkl 
(I got my output but it has a trailing space)
Notice the tiny difference? An additional space after \1. The space can be anywhere but has to be included to make sed print correctly. Other text in the output section does not help, there has to be a space, like /A \1/ or /\1hello world/. If it is the intended behavior of sed, then please instruct me how to make sed print the desired match without any space in the output.

Now using -re to simplify things:

Code: Select all

> echo "x:abc/def/x:ghi/jkl/x:mno/pqr" | sed -re 's/x:[a-z\/]+x:ghi([^:]+)\/x:.*/\1/'
/jklno/pqr
(what happened here?? (if I add a space aroung \1 it's fine))
I believe this is the reason why TeTeX is not working on OS4 (anymore). It can't generate fonts because it can't extract paths properly. I was trying to patch-fix the scripts but then realized there has to be a bug in sed.

> which sed
Project:SDK/Local/C/sed
> sed --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

Re: sed on OS4 is buggy

Posted: Thu Aug 28, 2014 12:50 pm
by salass00
@Deniil

This doesn't help with your problem but just so you know you can avoid the ugly "picket fence" constructs ("\/") in your sed commands by using a different separator than forward slash, like underscore f.e.:

Code: Select all

echo "x:abc/def/x:ghi/jkl/x:mno/pqr" | sed -re 's_x:[a-z/]+x:ghi([^:]+)/x:.*_\1_'
Useful if you have to do matching with a lot of forward slashes.

Re: sed on OS4 is buggy

Posted: Thu Sep 18, 2014 6:05 pm
by broadblues
Sed has been broken for a long time.

I've replaced it with an older one, I may have built it myelf can't remeber now. The core-utils haven't been upgraded in ages, and sed got broken with the last update.



10.AmigaOS4:> `which sed` --version
GNU sed version 3.02

Copyright (C) 1998 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
10.AmigaOS4:> sdk:local/c/sed.mine --version
GNU sed version 3.02

Copyright (C) 1998 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
10.AmigaOS4:> sdk:local/c/sed.sdk --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

Re: sed on OS4 is buggy

Posted: Fri Sep 19, 2014 4:11 pm
by xenic
broadblues wrote:Sed has been broken for a long time.
Apparently it's broken since SDK 51.22. The 4.1.4 version from SDK 51.15 seems to work. I don't know anything about sed but when I copied your original test line and used it with sed 4.1.4, I got the result you were expecting. The current GNU version is up to 4.2 on their WEB site.