in reply to Re: Delete line if REGEX == true in thread Delete line if REGEX == true
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.
Re^3: Delete line if REGEX == true
by castaway (Parson) on Aug 07, 2005 at 15:24 UTC
|
There is too. Add an -i.bak and forget the redirection. See perlrun for -i.
C. | [reply] [d/l] |
|
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.
| [reply] [d/l] |
|