LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-17-2008, 03:11 AM   #1
ASRaj
LQ Newbie
 
Registered: Mar 2008
Posts: 20

Rep: Reputation: 0
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.
 
Old 03-17-2008, 03:28 AM   #2
hro
LQ Newbie
 
Registered: Jan 2008
Distribution: OpenSuse 10.3, SLED 10 SP2, Ubuntu 8.04 and 9.04
Posts: 23

Rep: Reputation: 15
cat run.tcl | sed s/'home\/aruna\/WORK\/GUI_test\/testharness'/($path)/ >> run1.tcl
 
Old 03-17-2008, 03:55 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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
 
Old 03-17-2008, 04:01 AM   #4
ASRaj
LQ Newbie
 
Registered: Mar 2008
Posts: 20

Original Poster
Rep: Reputation: 0
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.
 
Old 03-17-2008, 04:20 AM   #5
talha.rizwan
LQ Newbie
 
Registered: Sep 2007
Posts: 3

Rep: Reputation: 0
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
 
Old 03-17-2008, 05:09 AM   #6
ASRaj
LQ Newbie
 
Registered: Mar 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Hi,

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

Regards,
Aruna.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with SED in BASH Script stlouis Programming 2 01-22-2008 02:21 PM
SED in BASH Script - Syntax Problem stlouis Programming 4 01-13-2008 10:38 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
bash Problem with "sed" command blubbfish Linux - Newbie 3 06-01-2004 10:14 AM
problem with sed in a bash script nexus55 Linux - Software 6 05-03-2004 09:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration