Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Regular Expression to delete lines in text file?

Status
Not open for further replies.

dmoonme

MIS
Jul 21, 2004
33
0
0
US
I am a newbie using RegEx but what I want to do is delete 3 lines in a text file (ie. headers). The header always starts with the text "1PAGE" so I'm assuming this is what we want to match.

Here's what the header contains.

1PAGE 1 RPT-978 'delete this line
DATE 12/06/04 'delete this line
0PLAN 2-92001 'delete this line


Thanks for your help!
 
You are going to have to read in the input file, line at a time and just don't print out the output lines you don't want.

There is no way to "remove" lines in an existing file. You could NULL them out with spaces or whatever, but that only works if you don't change the size of the file. But, for the most part, just write a new file. You could read the file into a string, delete the original and write back to the same file name, but you better be sure you have the mother of all Try blocks in there.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top