Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Contents of gaurav.txt file

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

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

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

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

Your Answer


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.