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

Re: [Sheflug] Replacing a block of text in a file with text from another file



And Lo! The Great Prophet Jens Thomas uttered these words of wisdom:
> Thanks for the tips David and Chris - I really appreciate you taking the 
> time to give me your suggestions.
> 
> I fiddled around a bit more and have managed to come up with a 
> work-around, although it looks pretty horrible, and I'm sure there's a 
> neater way to do it .
> 
> #!/bin/bash
> sed -e '/zmatrix angstrom/,/end/cREPLACEME' <$1 >$1.tmp
> sed '/REPLACEME/ {
> r basis.txt
> d
> }' <$1.tmp >$1._in
> rm $1.tmp
> 

You can get rid of the temporary file by piping:

sed -e '/zmatrix angstrom/,/end/cREPLACEME < infile | sed -e '/REPLACEME/ {
r basis.txt
d
} > outfile

It'd be nice to get rid of the pipe, but I've not worked that out yet; just
doing sed -e ... -e ... doesn't seem to do the job. I'll ponder more...

Chris...

-- 
\ Chris Johnson                 \ NP: Electropop - 09. Midge Ure - If I Was
 \ cej [at] nightwolf.org.uk          \  
  \ http://cej.nightwolf.org.uk/  \ 
   \ http://redclaw.org.uk/        ~---------------------------------------


___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.