Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Delete specific lines from txt file.

by roboticus (Canon)
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 romping around the Monastery: (5)
As of 2014-12-27 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls