LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem in using sed commnad in bash program. (https://www.linuxquestions.org/questions/programming-9/problem-in-using-sed-commnad-in-bash-program-628584/)

ASRaj 03-17-2008 03:11 AM

Problem in using sed commnad in bash program.
 
hi All,

here is my problem
I try to use "sed" command as followig but I got error!

path=(`pwd`)
.
.
sed 's/home\/aruna\/WORK\/GUI_test\/testharness/($path)/g' run.tcl >> run1.tcl


I cann't figure out what is the problem with this. When I print path on screen it was having a correct value.

I think the problem is that path is having "/" characters inside it.

can you please give me a solution for this?

Thanks,
Aruna.

hro 03-17-2008 03:28 AM

cat run.tcl | sed s/'home\/aruna\/WORK\/GUI_test\/testharness'/($path)/ >> run1.tcl

konsolebox 03-17-2008 03:55 AM

Code:

path=(`pwd`)
you're trying to save the output as an array..
that should be
Code:

path="`pwd`"
then use @ as a replacement for forwardslash so that you don't have to quote them anymore
Code:

sed s@home/aruna/WORK/GUI_test/testharness@"${path}"@g run.tcl >> run1.tcl

ASRaj 03-17-2008 04:01 AM

hi,

It's not working and following is the error message


/home/aruna/WORK/GUI_test/testharness

./rtest: line 46: syntax error near unexpected token `('
./rtest: line 46: ` cat run.tcl | sed

s/'home\/aruna\/WORK\/GUI_test\/testharness'/($path)/ >> run1.tcl'



Thanks,
Aruna.

talha.rizwan 03-17-2008 04:20 AM

Hi,
Below is a code that should work fine. The problem is with the "pwd" command, because it returns the value something like "/home/arun". Which contains "/" slashes and you were passing it as it to sed without using the "\" slashes. So, you first need to convert "/" slashes to "\/":

path=$(pwd)
path=$(echo $path | sed 's/\//\\\//g')
.
.
.
sed 's/home\/aruna\/WORK\/GUI_test\/testharness/$path/g' run.tcl >> run1.tcl

Regards,
--Talha

ASRaj 03-17-2008 05:09 AM

Hi,

Thanks very much for the help and the lesson. It is working fine.

Regards,
Aruna.


All times are GMT -5. The time now is 08:51 AM.