user
08-01-2006, 08:42 PM
Hi,
I have a file and I need to remove a particular line from it. Any ideas how?
Thanks
I have a file and I need to remove a particular line from it. Any ideas how?
Thanks
|
Click to See Complete Forum and Search --> : Remove a line from a file user 08-01-2006, 08:42 PM Hi, I have a file and I need to remove a particular line from it. Any ideas how? Thanks PineSolPirate 08-02-2006, 01:12 PM Do you have any way of identifying the exact line? E.G. Do you know the line number, or does it follow a specific pattern or have a unique bit of content on it? user 08-02-2006, 01:38 PM Yes, I know what I'm looking for; it should match $line Thank you. PineSolPirate 08-02-2006, 01:45 PM Here is a start. I'm pretty sure that this won't work because I don't think variables get interpolated inside of the // for regexs. Don't know since I don't have Perl here at work. When I get home I'll work it out, if you don't get it first. $file = '/path/to/file.txt'; open(INFO, $file); @lines = <INFO>; close(INFO); foreach (@lines) { if($_ =~ /$line/) { // Code to remove this array index... } // Code to write it back to a file... user 08-02-2006, 05:07 PM I got it. Thank you! webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |