David Blevins wrote:
: There has to be a better way to modify/delete lines in a file than this.
Time for a one-liner:
perl -ni -e 'print unless /I'm a bad line, delete me\./' thefile
-n loops through the lines of thefile, but doesn't print them unless you ask
-i edits thefile in place
-e means the next thing on the command line is a Perl script
You can also do this in a script:
#!/bin/perl -ni
print unless /I'm a bad line, delete me\./;
-i can also take a string as an argument which becomes the extension of
the original file. So if you say "perl -ni.bak -e '...' thefile",
thefile will be edited, and the original will be saved in thefile.bak.
I strongly recommend this because it's so easy to screw up an in-place
edit.
-- tdk