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

Re: Save all but line 32!

by perrin (Chancellor)
on Sep 18, 2002 at 16:30 UTC ( #198901=note: print w/replies, xml ) Need Help??


in reply to Save all but line 32!

Not as fast and doesn't handle a list of files, but for entertainment value:
perl -MTie::File -e 'tie @file, 'Tie::File', $ARGV[0]; splice @file, 3 +1, 1;' filename
(Tie::File is in the standard lib now.)

Replies are listed 'Best First'.
Re^2: Save all but line 32!
by Aristotle (Chancellor) on Sep 18, 2002 at 19:20 UTC
    Some None of the other solutions will not correctly handle a list of files either (only the ones using $. will). And this one is easily extended to do so: perl -MTie::File -e 'tie(@file, 'Tie::File', $_) and splice @file, 31, 1 for @ARGV' file1 file2 file3 Update: zigdon is right. I should have tested.

    Makeshifts last the longest.

      I thought $. only resets on a close call? meaning the <> operator doesn't reset it, since it never closes the filehandles. So the following code will omit the 35th line only for the first file, but not for any other file:
      perl -ne 'print unless $. == 35' file1 file2
      Is that correct?

      -- Dan

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2020-10-31 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (291 votes). Check out past polls.

    Notices?