The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: sed error
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 04-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Shivdatta: Actually you probably mean


Code:
sed 's/FIT00/FIT01/g' filename

Your expression will replace only one occurrence (the last I believe) because of the wildcards which make it match the whole line.

But I guess what's asked for is really


Code:
sed "s%$S00%$S01%g" file

Single quotes force the strings to be taken literally; no quotes will give you a syntax error for many complex strings. To interpolate a variable into a string, put it in double quotes.

Of course, if you meant the substitution to contain literal single quotes, put them back in.

The "unknown option to s" error happens because the interpolated string contains slashes. Sed has no way to know which slashes were interpolated (this happens in the shell, before sed executes) so you need to use a different separator than the slash. (Fortunately in this case you know there are no percent signs in these variables. It's tougher when you can't know in advance whether or not a particular character could be included in a variable.)

Last edited by era; 04-28-2008 at 09:50 AM.. Reason: Explain quoting and cause of error message