Dru has asked for the wisdom of the Perl Monks concerning the following question:
Thanks,#!/usr/bin/perl -w use strict; my $ip = '192.168.1.4; my $txt = 'Removed ' . $ip . ' by Dru'; my $file = '/data/syslog/log.backup'; open (FILE, "+<$file") or die "Can't open $file: $!\n"; while (<FILE>){ if (/.*\b$ip\b.*/){ # I thought this would work, but it doesn't s/$_/$txt/; print FILE; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replacing Lines in a File
by dragonchild (Archbishop) on May 26, 2004 at 18:58 UTC | |
by Dru (Hermit) on May 27, 2004 at 03:20 UTC | |
|
Re: Replacing Lines in a File
by Stevie-O (Friar) on May 26, 2004 at 19:52 UTC | |
|
Re: Replacing Lines in a File
by punkish (Priest) on May 26, 2004 at 19:17 UTC |