1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#!/usr/bin/perl -w
use strict;
use Carp;
sub rename_file {
unlink $_[0] and rename ($_[1], $_[0]) and unlink $_[1];
}
#Fichier en lecture
open FILE,"< peuf.txt" or die "$!\n";
#Fichier en ecriture
open FILE_DEST,"> peuf2.txt" or die "$!\n";
while(<FILE>){
chomp;
#On prend exemple la modification de WID2
if(/WID2/){
#On va supposer que l'on modifie si on trouve LHE
if (/LHE/){
s/LHE\s.{3}\s/LHE 000 /;
print FILE_DEST $_."\n";
}
else {
print FILE_DEST $_."\n";
}
}
else {
print FILE_DEST $_."\n";
}
}
close FILE and close FILE_DEST;
rename_file("peuf.txt", "peuf2.txt"); |