Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Delete specific lines from txt file.

by trizen (Hermit)
on Aug 07, 2012 at 07:35 UTC ( #985902=note: print w/ replies, xml ) Need Help??

in reply to Delete specific lines from txt file.

See perldoc Tie::File.

Here is a sample code:

use strict; use warnings; use Tie::File; my $filename = '/path/to/file.txt'; my $firstname = 'John'; my $lastname = 'Watter'; tie my @array, 'Tie::File', $filename or die $!; for(my $i = 0; $i <= $#array; $i++){ if($array[$i] =~ /\b$firstname\b.+\b$lastname\b/){ splice(@array, --$i, 5); } } untie @array;

Comment on Re: Delete specific lines from txt file.
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985902]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2015-11-28 20:26 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (744 votes), past polls