Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Contents of gaurav.txt file

$generalNetPath = "/net";
$generalNetPath = "/glbusers4/glb/aimsys/apxwrk48";

I trying to replace /glbusers4/glb/aimsys/apxwrk48 by pwd as follows

qaz=`pwd`
sed '/apxwrk/c\$generalNetPath = "$qaz";' gaurav.txt

I am getting the output as

$generalNetPath = "/net";
$generalNetPath = "$qaz";

I was expecting $qaz be replaced by my present working directory.As far as my knowledge this is happening because of ' (single quotes) that I am using.I have tried using \ before " but that didn't help.Is there any anyway can I do this.I mean can I use anything other than ' so that I can have value of $pwd replaced by using any character other than ' .I tried using | but didn't work.Please help me out with this.

share|improve this question
    
Note that in POSIX shells, the current working directory is in the $PWD variable. –  Stéphane Chazelas Feb 15 '13 at 17:41
add comment

1 Answer

I figured it out myself.Here is the syntax.Thanks anyway.

sed "/apxwrk/c\$generalNetPath = \"$qaz\";" gaurav.txt
share|improve this answer
    
Yes or you could also use single quotes on the inside, which would work better in some circumstances (and worse only in the circumstance that your working directory name includes single quotes). –  dubiousjim Jan 11 '13 at 13:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.