The UNIX and Linux Forums
>
Top Forums
>
Shell Programming and Scripting
sed error
.
User Name
Remember Me?
Password
google unix.com
Forums
Register
Forum Rules
Links
Albums
FAQ
Members List
Calendar
Search
Today's Posts
Mark Forums Read
Thread
:
sed error
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
#
7
(
permalink
)
04-28-2008
era
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
era
View Public Profile
Visit era's homepage!
Find all posts by era
Find era's past nominations received
Find era's present nominations given