sed on OS4 is buggy

Have a question about our Software Developer Kit? Ask them here.

sed on OS4 is buggy

Postby Deniil » Thu Aug 28, 2014 11:53 am

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.
Deniil
 
Posts: 108
Joined: Mon Jul 11, 2011 7:59 pm

Re: sed on OS4 is buggy

Postby salass00 » Thu Aug 28, 2014 1:50 pm

@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
salass00
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 516
Joined: Sat Jun 18, 2011 4:12 pm
Location: Finland

Re: sed on OS4 is buggy

Postby broadblues » Thu Sep 18, 2014 7:05 pm

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

Re: sed on OS4 is buggy

Postby xenic » Fri Sep 19, 2014 5:11 pm

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
xenic
 
Posts: 1160
Joined: Sun Jun 19, 2011 1:06 am


Return to SDK Support

Who is online

Users browsing this forum: No registered users and 2 guests