Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Delete line if REGEX == true

by AReed (Pilgrim)
on Aug 07, 2005 at 05:27 UTC ( [id://481617]=note: print w/replies, xml ) Need Help??


in reply to Delete line if REGEX == true

However, if you insist on using perl... ;-)
use strict; use warnings; while (<>) { print unless /,,,,,/; }

...will do it. Or the command-line equivalent:

perl -ne "print unless /,,,,,/" infile > outfile

Please note that I only tested this under Windows, so you may have to change double-quotes to single-quotes on a Unix system.

Replies are listed 'Best First'.
Re^2: Delete line if REGEX == true
by sgifford (Prior) on Aug 07, 2005 at 06:49 UTC
    The key observation here is that you're making a copy of the file without those lines in it. There's no straightforward way to delete the lines directly from the file; instead you have to think about it slightly backwards: print the lines you want to keep, and just skip the ones you want to delete. When you're done, you can rename the new file onto the original, or you can use perl's -i switch to take care of that for you.
      There is too. Add an -i.bak and forget the redirection. See perlrun for -i.

      C.

        The -i flag causes perl to do exactly what I've described above. It's shorter syntax, sure, but it still copies the parts of the file you want to keep, then renames the resulting file.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found