This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Portable Cygwin: replacing drivename in a text file


Am 25.11.2010 14:29, schrieb Alexandre Bezroutchko:
Hi Fergus,

The problem is $HOME contains '/' character used as delimited in regex. You need to escape it first:

HOME_ESCAPED=`echo "$HOME" | sed 's#/#\\\\/#g'`
echo 123 | sed "s/2/$HOME_ESCAPED/g"

It is not cygwin-specific.

Cheers,
Alex
www.gremwell.com

On 11/25/2010 02:15 PM, Fergus wrote:
I can't get the syntax quite right.
Can anybody help, please? Thank you very much.

Thanks very much indeed for various suggestions, much appreciated. I guess by yakking on about "drivename" I moved the focus of my question to its practical application and thereby managed to blur things. My real question is

Given the string 123 how can I use sed to change it to 1$HOME3 or, in my
case, 1/home/user3. Various combinations of ' " and ` (also arbitrary
separators) all fail as in

echo 123 | sed 's/2/"$HOME"/g'
echo 123 | sed 's/2/`$HOME`/g'
echo 123 | sed "s/2/'"$HOME"'/g"
echo 123 | sed 's/2/@$HOME@/g'

Thank you (again).

Fergus



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple




Hello Fergus,


you can use a different separator in the sed command.
You can use the following line

echo 123 | sed "s%2%${HOME}%g"

Regards
Dirk


-- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]