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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-20-2005, 12:02 PM
|
#1
|
|
Member
Registered: Jul 2005
Posts: 140
Rep:
|
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.
|
|
|
|
07-20-2005, 12:35 PM
|
#2
|
|
Member
Registered: Jan 2005
Distribution: Archlinux, Debian, grml
Posts: 210
Rep:
|
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
|
|
|
|
07-20-2005, 01:59 PM
|
#3
|
|
Member
Registered: Jul 2005
Posts: 140
Original Poster
Rep:
|
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.
|
|
|
|
07-20-2005, 02:14 PM
|
#4
|
|
Moderator
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,505
Rep: 
|
That could be due to the contents of $MAP. please 'echo $MAP' for us here. 
|
|
|
|
07-20-2005, 02:58 PM
|
#5
|
|
Member
Registered: Jul 2005
Posts: 140
Original Poster
Rep:
|
It is a constant I defined in the beginning: $MAP='"4RFh\,SAHg\,tBds"'
|
|
|
|
07-20-2005, 03:04 PM
|
#6
|
|
Moderator
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,505
Rep: 
|
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.
|
|
|
|
07-20-2005, 03:25 PM
|
#7
|
|
Member
Registered: Jul 2005
Posts: 140
Original Poster
Rep:
|
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.
|
|
|
|
07-20-2005, 10:38 PM
|
#8
|
|
Moderator
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,505
Rep: 
|
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?
|
|
|
|
07-24-2005, 05:57 PM
|
#9
|
|
Member
Registered: May 2005
Posts: 378
Rep:
|
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).
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:42 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|