sed on OS4 is buggy

Have a question about our Software Developer Kit? Ask them here.
Post Reply
Deniil
Posts: 109
Joined: Mon Jul 11, 2011 6:59 pm

sed on OS4 is buggy

Post 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.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

Re: sed on OS4 is buggy

Post 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.
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: sed on OS4 is buggy

Post 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.
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: sed on OS4 is buggy

Post 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.
AmigaOne X1000 with 2GB memory - OS4.1 FE
Post Reply