sed error
hello, in a ksh script I have
sed "s/\/\([a-ZA-z]*\)/[[$str\/\1]]/g" where $str was a string stored earlier in this kornshell script. For example, the script stored "cheese" in $str. Then it would substitute /Burger with [[cheese/Burger]]. However I get a "sed statement not closed" error. What's wrong with my syntax? Thanks in advance. |
Hi,
Maybe you didn't give all the info needed, 'cause the following seems to work: Code:
#!/bin/ksh Code:
$ cat infile I tested this on SUN hardware with solaris 9. In general solaris is less forgiving then linux, in this case it is the opposite. The [a-ZA-z] part will not work with linux, it does with solaris. Sorry for the confusion. |
The problem is [a-ZA-z], which should be [a-zA-Z]. Think of ranges of character as their ASCII values. Saying [a-z] is like saying (pseudocode):
Code:
if ( char >= ascii('a') && char <= ascii('z') ... Code:
if ( char >= 97 && char <= 90 ) ... |
thanks, I can't believe I didn't catch that. My problem now is that it doesn't interpret $str as a variable, but a literal; my result is [[$str/burger]] instead of [[cheese/burger]]; how do I fix this?
|
Hi,
Which quotes are you using around the sed statement: single or double? It should be double quotes, as shown in the example in my previous post. If that is not the case, could you post the code you are using so we can have a look? |
All times are GMT -5. The time now is 12:50 PM. |