in reply to Deleting a line out of text file
Your problem is that you cannot just edit a file in place. All you are changing is the line which is in a variable in memory, it never gets to the disk. The most concise way to do this is to open the file, and then print out all the lines except the one you don't want. Then you can redirect the output to another file. Also, some of perl's command-line arguments can help you accomplish that:
#!/usr/bin/perl -nw use strict print unless /$var/i; # or a perl one-liner perl -i.bak -nwe 'print unless /019/i' <file>
HTH
Addendum: RE: Abigail's comments: Added the -e switch. And the 'gi' is just following the orginal poster since 019 may not be the only data (s)he is looking for, didn't want the confuse the issue if they plugged in some other data and it was missing. I suppose the 'g' is superfluous in this case, guess you can safely remove that one.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Deleting a line out of text file
by Abigail-II (Bishop) on Aug 13, 2003 at 15:36 UTC | |
|
Re: Re: Deleting a line out of text file
by Anonymous Monk on Aug 13, 2003 at 17:11 UTC | |
by dga (Hermit) on Aug 13, 2003 at 17:35 UTC | |
by kesterkester (Hermit) on Aug 13, 2003 at 19:03 UTC | |
by Anonymous Monk on Aug 13, 2003 at 17:53 UTC | |
by dga (Hermit) on Aug 13, 2003 at 21:24 UTC | |
|
Re: Re: Deleting a line out of text file
by crouchingpenguin (Priest) on Aug 14, 2003 at 02:38 UTC |