Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Delete specific lines from txt file.

by roboticus (Chancellor)
on Aug 07, 2012 at 02:41 UTC ( #985865=note: print w/ replies, xml ) Need Help??


in reply to Delete specific lines from txt file.

FredFredFred:

What part are you having trouble with? If it's actually removing the data from the file, then a typical method to do it is to write the data you want to keep to a new file. Then rename your data file to a backup version, and rename your new file with the original name.

You're welcome, and good luck.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


Comment on Re: Delete specific lines from txt file.
Re^2: Delete specific lines from txt file.
by FredFredFred (Initiate) on Aug 07, 2012 at 23:15 UTC

    hmm, that sounds good, but I have no clue how to do it... Can you provide some code? Thanks

      FredFredFred:

      # Discard every other line open FIN, 'INFILE' or die; open FOUT, '>INFILE.new' or die; my $cnt; while (<FIN>) { next if $cnt%2; print FOUT; } close FH; close FOUT; rename 'INFILE', 'INFILE.bak'; rename 'INFILE.new', 'INFILE;

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2015-07-06 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls