LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-20-2005, 12:02 PM   #1
ShaqDiesel
Member
 
Registered: Jul 2005
Posts: 144

Rep: Reputation: 15
sed


In a kornshell script I am trying to do a search and replace of file path strings in multiple files. I try sed but it doesn't like the " at the end of my replacement string. It gives me the error "sed:extra text at end of command". How can I get around this? Thanks.
 
Old 07-20-2005, 12:35 PM   #2
traene
Member
 
Registered: Jan 2005
Distribution: Archlinux, Debian, grml
Posts: 210

Rep: Reputation: 33
Maybe you must escape the " sign. Can you post your command?
Or you can try the cut command. You can cut on character positions:

echo $line | cut -cPOS1-POS2

or on distinct signs
echo $line | cut -d/ -f1-3
 
Old 07-20-2005, 01:59 PM   #3
ShaqDiesel
Member
 
Registered: Jul 2005
Posts: 144

Original Poster
Rep: Reputation: 15
Thanks, I fixed that problem except i get an error not recognizing -e when I type

sed -e "s/^Data_filename = .*/Data_filename = \"Results\$filename\"/g" \
-e "s/^map_used = .*/map_used = $MAP/g" \
-e "s/^location = .*/location = $LOC/g" $I > temp
when I get rid of the map_used line it works, so what is going on? Thank you.
 
Old 07-20-2005, 02:14 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
That could be due to the contents of $MAP. please 'echo $MAP' for us here.
 
Old 07-20-2005, 02:58 PM   #5
ShaqDiesel
Member
 
Registered: Jul 2005
Posts: 144

Original Poster
Rep: Reputation: 15
It is a constant I defined in the beginning: $MAP='"4RFh\,SAHg\,tBds"'
 
Old 07-20-2005, 03:04 PM   #6
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Your constant makes the line look like:
Code:
 -e "s/^map_used = .*/map_used = "4RFh\,SAHg\,tBds"/g" \
Seems the s/// construct has a closing quote before the 4.

When you define MAP, try escaping the double-quotes.
 
Old 07-20-2005, 03:25 PM   #7
ShaqDiesel
Member
 
Registered: Jul 2005
Posts: 144

Original Poster
Rep: Reputation: 15
I want the replacement string to have the quotes; I tried defining MAP again like \"STRING\" but it still gives me that error not recognizing sed's -e extension.
 
Old 07-20-2005, 10:38 PM   #8
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
You may need two backslashes when escaping it. I have to play around with those sometimes. What is the exact text of the error you get?
 
Old 07-24-2005, 05:57 PM   #9
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
Originally posted by ShaqDiesel
Thanks, I fixed that problem except i get an error not recognizing -e when I type

sed -e "s/^Data_filename = .*/Data_filename = \"Results\$filename\"/g" \
-e "s/^map_used = .*/map_used = $MAP/g" \
-e "s/^location = .*/location = $LOC/g" $I > temp
when I get rid of the map_used line it works, so what is going on? Thank you.
I bet you've got a space after the backslash on the MAP line. The backslash must be the last character on the line. The shell is ending the sed command because the newline isn't escaped, and is trying to run the next line as a new command (-e: command not found).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Sed q? ky-lab_rat Linux - Software 5 10-26-2004 07:59 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
Help with sed odious1 Linux - General 2 08-29-2003 10:52 AM
help with sed DavidPhillips Programming 3 08-11-2003 04:46 PM


All times are GMT -5. The time now is 11:22 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration