Shaf said:
I am new to Perl and have a question regarding deleting header data
from a text file. I have a set of files that I need to delete data
from. Is there something in Perl to delete string data? What is the
best way for me to handle this?
There are no good ways to simply remove arbitrary text from an existing
file. The general way to do what you want it to open the existing file,
read it, close it, modify the data as needed, re-open the file for
writing (thus eliminating all previous contents), and write the modified
data to the file.
Perl gives a very quick way to do this, via the -n and -i options. You
can read about them by typing
perldoc perlrun
into your command line
In general, you can accomplish your goal like this:
perl -ni.bak -e 'print unless /HEADER/' file.txt
This will remove all lines from file.txt which contain 'HEADER'. It
will save a backup of the original file as file.txt.bak, just in case.
Hope this helps get you started
Paul Lalli