[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regular expression replacement in SED.





On Wed, 5 Apr 2000, Robert Speed wrote:

> Quick question for any sed people;
> 
> I'm trying to perform a regular expression replacement from sed
> but by passing params within a bash script.
> However, I'm a tad stuck at how to force the command line
> to stop interpreting white space literally.
> 
> ie.
> if (from the cli) I ;
> sed 's/%NAME%/Fred Flintstone/' letterin > letterout
> 
> I can replace all instances of %NAME% in letterin with
> Fred Flintstone and send the output to letterout.
> 
> Fine, fair enough.
> The problem I have now is how to automate this from within a shell 
> script.
> 
> So, what I have in the script is the following;
> 
> SedCommand=\'s\/%NAME%\/$Recipient\/\'
> echo sed $SedCommand $InputDoc \> $DocToSend
> sed $SedCommand $InputDoc > $DocToSend

sed "s/%NAME%/$Recipient/" $InputDoc > $DocToSend

or

SedCoomand="s/%NAME%/$Recipient/"
sed "$SedCommand"  $InputDoc > $DocToSend


> 
> (Note, that they're not Vs in there, but escaped \ !)
> Now this is giving the output;
> 
> sed 's/%NAME%/Robert Speed/' letter2 > form_rms.doc
> sed: 's/%NAME%/Robert is not a recognized function.
> 
> The key point here is that the command line is interpreting the 
> space in the variable $Recipient literally.
> The variable has previously been read in from another file, and so
> will never be the same for each iteration. 
> 
> (Now, this is just one step within the script, there's loads of other 
> stuff going on, it's just that this bit is as crucial as any other).
> 
> I've tried 'escaping' the name in the source datafile (where the 
> recipients name is coming from), but to no avail...
> 
> Anyone any ideas ???
> 
> 
> Rob S.
> Vickers (Laboratories) Ltd.
> Grangefield Industrial Estate, Pudsey, Leeds LS28 6QW
> Switchboard: +44 (0)113 236 2811   Fax: +44 (0)113 236 2703
> 
> All opinions are my own and ! Vickers.
> The nice thing about Windows is that it doesn't just crash.
> It displays a dialogue box and lets you click OK first.
> ---------------------------------------------------------------------
> Sheffield Linux User's Group - http://www.sheflug.co.uk
> To unsubscribe from this list send mail to
> - <sheflug-request [at] vuw.ac.nz> - with the word 
>  "unsubscribe" in the body of the message. 
> 
>   GNU the choice of a complete generation.
> 
> 
> 

---------------------------------------------------------------------
Sheffield Linux User's Group - http://www.sheflug.co.uk
To unsubscribe from this list send mail to
- <sheflug-request [at] vuw.ac.nz> - with the word 
 "unsubscribe" in the body of the message. 

  GNU the choice of a complete generation.