Koozali.org: home of the SME Server
Legacy Forums => Experienced User Forum => Topic started by: Darrell May on October 13, 2001, 08:12:22 AM
-
I need to open a text file, perform a substitution on a word and save the file.
Just as an example, lets say I want to open /etc/lilo.conf and change every occurance of the word 'e-smith' to 'mitel'. Again, just a file example.
[root@e-smith lilo.conf]# cat /etc/lilo.conf
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
message=/boot/e-smith.pcx
linear
default=esmith
image=/boot/vmlinuz-2.2.16-22
label=esmith
read-only
root=/dev/hda6
As you can see there are three changes to be made. How may this be done using a perl script?
Darrell
-
Rather than fill this forum with vaugely off topic material, I might suggest to pose the question to one of the Perl support pages.
My personal pick is PerlMonks.org but I'm sure there's plenty of similar places around.
Regards,
Luke
-
How 'bout
perl -n -i.bkup -e 's/e-smith/mitel/i; print;' /etc/lilo.conf
as a first guess?
Thanks,
jasonDarrell May wrote:
>
> I need to open a text file, perform a substitution on a word
> and save the file.
>
> Just as an example, lets say I want to open /etc/lilo.conf
> and change every occurance of the word 'e-smith' to 'mitel'.
> Again, just a file example.
>
> [root@e-smith lilo.conf]# cat /etc/lilo.conf
> boot=/dev/hda
> map=/boot/map
> install=/boot/boot.b
> prompt
> timeout=50
> message=/boot/e-smith.pcx
> linear
> default=esmith
>
> image=/boot/vmlinuz-2.2.16-22
> label=esmith
> read-only
> root=/dev/hda6
>
> As you can see there are three changes to be made. How may
> this be done using a perl script?
>
> Darrell
-
jason wrote:
>
> How 'bout
>
> perl -n -i.bkup -e 's/e-smith/mitel/i; print;' /etc/lilo.conf
That works perfectly and makes a backup copy of the original.
Thanks Jason :->
Darrell