sed string replacements

Ryan Schmidt ryandesign at macports.org
Sat Jun 19 14:12:50 PDT 2010


On Jun 19, 2010, at 15:57, Scott Haneda wrote:

> On Jun 19, 2010, at 12:39 PM, Joshua Root wrote:
> 
>> On 2010-6-20 05:30 , Rainer Müller wrote:
>>> On 2010-06-19 21:05 , Scott Haneda wrote:
>>>>   sed -e '/_VERSION_HEADER_/$VERSION_HEADER' DOCUMENTATION
>>>>   sed -e '/_TOKEN_/$DOWNLOAD' DOCUMENTATION
>>>>   sed -e '/_OTHER_TOKEN_/$ALT_DOWNLOAD' DOCUMENTATION
>>>             ^
>>> 
>>> You would need:
>>>     sed -e 's/_VERSION_HEADER_/$VERSION_HEADER/' DOCUMENTATION
>> 
>> Using single quotes here is also going to stop the variables from being
>> substituted
> 
> Thanks.  Well, at least it is not just me that is getting stuck on this one.  I have tried the above, with ' and with " to no promising results.
> 
>    $cat maker 
>    #!/bin/bash
>    VERSION_HEADER=`cat VERSION.header`
>    #echo "$VERSION_HEADER"
> 
>    sed -e "s/_VERSION_HEADER_/$VERSION_HEADER/" DOCUMENTATION
> 
> $./maker 
> sed: 1: "s/_VERSION_HEADER_/# Hi ...": unescaped newline inside substitute pattern

Yup, sed doesn't do multiline replacements easily.

I'd probably write a php or perl script to do this; much more flexible than a shell script.



More information about the macports-dev mailing list