develooper Front page | perl.beginners | Postings from March 2002

Doing work on a file.. Spliting up the file

From:
Steven M. Klass
Date:
March 21, 2002 10:54
Subject:
Doing work on a file.. Spliting up the file
Message ID:
200203211853.g2LIrrw07807@vivids1.nsc.com
Hi all,

	I am still trying to find a suitable way to split up a file.  I have 
attached a sample file for your viewing pleasure.  This file is a standard 
text file that I need to work on.

Here is the basic idea of what I'm trying to do.
1.  I ONLY want to work on the area from *DESCRIPTION to *ENDS.  Everything 
else is irrelavant, but needed in the final document.
2.  Comments (";") should be ignored but carried with the document.
3.  I want to be able to do an enhanced search and replace, where if you 
don't find it, add in the line.  For example in the test file, there is a line
	OUTLIB		= lvsout	
replace this with OUTLIB = TEST.  Now if you don't find it add in (just 
before the *ENDS) OUTLIB = TEST

I don't know how to do this nicely.  For 1. do I read in the document as a 
whole or split it with \n^*\w (look for a newline with a * at the beginning 
of a line - my regex is probably hosed..), And if I do this how do I keep the 
comments?

How do I ignore the comments period if I split this up?

For number 3 I can't come up with a way to look in a section and if you don't 
find it, add it to the end?  I am clueless here.

Any help would be greatly appreciated.

Thanks so much
-- 

 Steven M. Klass
 Physical Design Manager

 National Semiconductor Corp
 15210 S. 50th Street
 Suite 120, Mail Stop AZ4
 Phoenix, AZ 85044

 Ph:480-629-2503
 Fax:480-629-2476

 steven.klass@nsc.com
 http://www.nsc.com


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About