[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



On Tuesday 10 August 2004 12:32, Jens Thomas wrote:
> Hello
>
> I've tried posting this to the Manchester Linux User Group, but haven't
> heard anything back, so I thought I'd try here - apologies to anyone who
> is on both groups and has seen this before!
>
> I'm trying to write a script that will go through a bunch of input files
> I have and replace all the text between the lines 'zmatrix angstrom' and
> 'end' with text the from a file (the input file is test.in and the text
> to be inserted from basis.txt in  the example below).
>
> I think that sed should be able to do the actual insertion bit, but I'm
> having no luck trying to work out exactly what I need to do. I've got as
> far as:
>
> sed -e '/zmatrix angstrom/,/end/{
> r basis.txt
> d}' < test.in
>
> which inserts the text from the file as many times as there are lines in
> the pattern between 'zmatrix angstrom' and 'end', whereas I just want
> the file inserted once for the entire block. I've tried several ways of
> doing this, but each time the action of inserting the file is repeated
> for each line and I can't work out how to specify the entire pattern as
> the entity to be replaced.
>
> Any hints on how to go about this would be greatly apreciated (I know
> this would be easy to do with something like Python or Perl, but I'd
> really like to try and do this with a bash script if at all possible).
>
> Many thanks in advance,
>
> Jens



 Don't use sed, I suspect perl would be a better bet but if not the sed faq
may be of help

http://www.student.northpark.edu/pemente/sed/sedfaq.html


Dave.



> ___________________________________________________________________
>
> Sheffield Linux User's Group -
> http://www.sheflug.co.uk/mailfaq.html
>
>   GNU the choice of a complete generation.

-- 
Dr. David Holden. (Systems Developer)
Crystallography Journals Online: <http://journals.iucr.org>

Thanks in advance:-
Please avoid sending me Word or PowerPoint attachments.
See: <http://www.fsf.org/philosophy/no-word-attachments.html>

Show me your papers..: http://www.no2id.net/index.html

Public GPG key available on request.
-------------------------------------------------------------
___________________________________________________________________

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

  GNU the choice of a complete generation.