Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Deleting first and last lines of a text file

by morgon (Deacon)
on May 16, 2014 at 12:00 UTC ( #1086293=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Deleting first and last lines of a text file
in thread Deleting first and last TWO(2) lines of a text file

This deletes the fist line and the last 2 lines of input.txt and keeps a copy of the old version in input.txt.old.

perl -i.old -ne 'my $l = <>; print($l), next if $.==2; print "$_$l" un +less eof' input.txt
Note that this is a one-liner to be run as is from the command-line (adjust your input file-name).


Comment on Re^3: Deleting first and last lines of a text file
Download Code
Re^4: Deleting first and last lines of a text file
by vsmeruga (Acolyte) on May 16, 2014 at 12:36 UTC
    It is taking so much time and not exiting when I run it as a one liner.
    perl -i.old -ne 'my $l = <>; print($l), next if $.==2; print "$_$l" un +less eof' /home/file_20140319.txt

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-12-25 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (160 votes), past polls