Re: sed problem: variables countaining special symbols



Andy B wrote:
Chris F.A. Johnson wrote:
On 2006-08-21, Andy B wrote:
Hi Guys,

Wonder if you can help, this problem is getting me down.

My script is falling over with a sed problem.

NEWSTORE=JvHCdEMzDegPI
NPASS=EoWH/Q4hds7nA

sed -e '/bill/s/'"${NEWSTORE}"'/'"${NPASS}"'/g' /tmp/temp

The above sed command works fine when there are no "special characters"
but when they appear as above i get a sed: command garbled: error.
Tried a few things with no luck, to escape theses.
That's bacause $NPASS contains a slash. Use a different delimiter
with sed:

sed -e "/bill/s|${NEWSTORE}|${NPASS}|g" /tmp/temp

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

Hi Chris,

Thanks for the reply.

I would love to do this only problem is that the 2 variables

$NEWSTORE and $NPASS, will be generated from a file that may have
special characters in it ie !"?$%^&* etc, so what i need sed to do is
read the variable in and ignore any special character that are in that
variable.

Is there a way round this at all?


The sed's I've used also accept control characters, eg. ctrl-G,
as substitute delimiters. Is there a possibility that your variables
will contain control characters too? If not, try a control char,
control X or control G or some such.

sed "/bill/s^X$NEWSTORE^X$NPASS^Xg"
.



Relevant Pages

  • A Christmas Present (that you didnt ask for)...
    ... it is written in vbs using api's called by DynaWrap to create the graphical interface. ... It has been mentioned in the scripting ng's for years and is frequently suggested for use when somebody wishes to do something outside the realm of "pure" script. ... It is possible to declare-and-call an api from script, but you must use a third-party control to do so, or else write one yourself. ... Private Function RepaintProgBar ...
    (microsoft.public.scripting.vbscript)
  • FYI: TS client script
    ... for TS on the machine running the script, ... the web control class was not found; ... Dim m_Tracing, m_TraceStream ... Function ArgString(ByVal argName, ByVal defaultValue) ...
    (microsoft.public.win2000.termserv.clients)
  • FYI: TS client script
    ... for TS on the machine running the script, ... the web control class was not found; ... Dim m_Tracing, m_TraceStream ... Function ArgString(ByVal argName, ByVal defaultValue) ...
    (microsoft.public.windows.terminal_services)
  • Re: Difficulties in deriving a truly universal GUI Scripting Language
    ... What the caret ... It could also control the mouse and the keyboard. ... From this information, the script could ... You would merely have to re-examine the screen display after every input ...
    (microsoft.public.vc.mfc)
  • Re: UCOMIStream, MSHTML and WebBrowser control Persistence Problem
    ... If I navigate to a file ... > the same html I cannot call into the same dhtml script function. ... It is best to retrieve it from the control each time ...
    (microsoft.public.dotnet.languages.vb)