LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed (https://www.linuxquestions.org/questions/programming-9/sed-345052/)

ShaqDiesel 07-20-2005 12:02 PM

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.

traene 07-20-2005 12:35 PM

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

ShaqDiesel 07-20-2005 01:59 PM

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.

Matir 07-20-2005 02:14 PM

That could be due to the contents of $MAP. please 'echo $MAP' for us here. :)

ShaqDiesel 07-20-2005 02:58 PM

It is a constant I defined in the beginning: $MAP='"4RFh\,SAHg\,tBds"'

Matir 07-20-2005 03:04 PM

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.

ShaqDiesel 07-20-2005 03:25 PM

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.

Matir 07-20-2005 10:38 PM

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?

eddiebaby1023 07-24-2005 05:57 PM

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).


All times are GMT -5. The time now is 05:46 AM.