[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



>
> 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'd use (and have used) perl to do this.  I had a template html file that
needed stats inserting at a certain point.

Not sure how good your perl is (hopefully better than mine) but the
structure should look a bit like this.

Read inputfile line
if inputfile line = starttag then {
	open insertfile
	read insertfile line by line
	write insert file lines to outputfile

	read input file until inputfile line = endtag #(this will skip to the end
of the bit to miss out)
      }
if inputfile line <> start tag and inputfile line <> end tag write inputfile
line to outputfile.

Hope this isn't too crypic.  I don't have time at the mo to put it in real
code and without testing I'd probably mix my php and perl together and leave
you with a load of useless code.

It can probably be done in a lot less code.  You have to get perl/sed etc to
match over multiple lines which I was never any good at and it took me less
time to code it in long hand than try to be clever and do it in a one liner.

HTH

Chris Johnson
(No not that one, the other one!)
(running SUSE 9, 512MB PIII 600 (ish))

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.734 / Virus Database: 488 - Release Date: 04/08/2004


___________________________________________________________________

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

  GNU the choice of a complete generation.