[PERL]- traduire du shell en perl
tonixm
Messages postés
127
Date d'inscription
Statut
Membre
Dernière intervention
-
tonixm Messages postés 127 Date d'inscription Statut Membre Dernière intervention -
tonixm Messages postés 127 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Avis aux habitués!!
je suis en train de me mordre les doigts sur une traduction d'un programme en perl:
cat $Conf_file | while read line
do
cat $File.sort | grep -v -w "$line" > $File.tmp
cat $File.tmp > $File.sort
done
cat $File.sort | sort >> $File.focal
Merci de tout coeur!!!
Avis aux habitués!!
je suis en train de me mordre les doigts sur une traduction d'un programme en perl:
cat $Conf_file | while read line
do
cat $File.sort | grep -v -w "$line" > $File.tmp
cat $File.tmp > $File.sort
done
cat $File.sort | sort >> $File.focal
Merci de tout coeur!!!
A voir également:
- [PERL]- traduire du shell en perl
- Classic shell - Télécharger - Personnalisation
- Comment traduire un site en français - Guide
- Traduire image - Guide
- Comment traduire sur whatsapp - Accueil - Messagerie instantanée
- Denon perl pro test - Accueil - Audio
90 réponses
par curiosité: as tu tester cette solution??
oui, je l'ai testé, mais c'est plutôt à toi de le faire ;-)
oui, je l'ai testé, mais c'est plutôt à toi de le faire ;-)
le soucis est que je ne peut pas afficher "$e:$_\n";" car ton script ne m'affiche que les lignes qui ont été enlevée mais il manque d'affichier avec, la ligne de .conf qui a permis de la retirée (ici $_ qui n'est pas sauvegardée)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
j ai fais ceci mais j'ai beaucoup de messages qui ne vont ni dans tmp ni dans debug:
my @conf=<CONF>; chomp @conf; while(my $e=<ANALYSE>){ print TMP $e unless grep { if($_=~/\|/){ my ($x,$y)=split /\|/,$_; $e=~ /$x.*$y/; if($e=~ m/$x.*$y/){ print DEBUG "$e:$_\n"; } }else{ $e=~/$_/; if($e=~ m/$_/){ print DEBUG "$e:$_\n"; } } } @conf; }
.analyse
Apr 22 10:59:22 vmonitor Server Administrator: line
Apr 22 10:58:49 vmonitor ntpd: ntpd 4.2.0a@1.1190-r Thu Oct 5 04:11:32 E
DT 2006 (1)
Apr 22 10:58:49 vmonitor ntpd: precision = 18.000 usec
Apr 22 10:58:49 vmonitor ntpd: Listening on interface wildcard, 0.0.0.0#1
23
Apr 22 10:58:49 vmonitor ntpd: Listening on interface wildcard, ::#123
Apr 22 10:58:49 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123
Apr 22 10:58:49 vmonitor ntpd: Listening on interface eth0, 172.16.15.39#
.conf
ntpd: precision
ntpd: Listening on
ntpd: ntpd
.tmp
RIEN alors qu'on devrait avoir : Apr 22 10:59:22 vmonitor Server Administrator: line
.debug
RIEN alors qu'on devrait avoir:
Apr 22 10:58:49 vmonitor ntpd: precision = 18.000 usec
:ntpd: precision
Apr 22 10:58:49 vmonitor ntpd: Listening on interface wildcard, 0.0.0.0#1
23
:ntpd: Listening on
Apr 22 10:58:49 vmonitor ntpd: Listening on interface wildcard, ::#123
:ntpd: Listening on
Apr 22 10:58:49 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123
:ntpd: Listening on
Apr 22 10:58:49 vmonitor ntpd: Listening on interface eth0, 172.16.15.39#
:ntpd: Listening on
Quelqu'un saurait d'où cela peut provenir.
Cet exemple est copié mot pour mot de mon fichier
Apr 22 10:59:22 vmonitor Server Administrator: line
Apr 22 10:58:49 vmonitor ntpd: ntpd 4.2.0a@1.1190-r Thu Oct 5 04:11:32 E
DT 2006 (1)
Apr 22 10:58:49 vmonitor ntpd: precision = 18.000 usec
Apr 22 10:58:49 vmonitor ntpd: Listening on interface wildcard, 0.0.0.0#1
23
Apr 22 10:58:49 vmonitor ntpd: Listening on interface wildcard, ::#123
Apr 22 10:58:49 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123
Apr 22 10:58:49 vmonitor ntpd: Listening on interface eth0, 172.16.15.39#
.conf
ntpd: precision
ntpd: Listening on
ntpd: ntpd
.tmp
RIEN alors qu'on devrait avoir : Apr 22 10:59:22 vmonitor Server Administrator: line
.debug
RIEN alors qu'on devrait avoir:
Apr 22 10:58:49 vmonitor ntpd: precision = 18.000 usec
:ntpd: precision
Apr 22 10:58:49 vmonitor ntpd: Listening on interface wildcard, 0.0.0.0#1
23
:ntpd: Listening on
Apr 22 10:58:49 vmonitor ntpd: Listening on interface wildcard, ::#123
:ntpd: Listening on
Apr 22 10:58:49 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123
:ntpd: Listening on
Apr 22 10:58:49 vmonitor ntpd: Listening on interface eth0, 172.16.15.39#
:ntpd: Listening on
Quelqu'un saurait d'où cela peut provenir.
Cet exemple est copié mot pour mot de mon fichier
Le problème, c'est qu'au début tu as demandé une chose et en final, tu veux des choses en plus.
Quand j'ai écrit le code je me suis limité à ta demande.
Voici pour tester
Toutefois il y a des doublons
Apr 11 16:51:34 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123 ::: ntpd:
Apr 11 16:51:34 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123 ::: ntpd: Listening on
Apr 11 16:51:34 vmonitor ntpd: Listening on interface eth0, 172.16.15.39#123 ::: ntpd:
Apr 11 16:51:34 vmonitor ntpd: Listening on interface eth0, 172.16.15.39#123 ::: ntpd: Listening on
Apr 11 16:51:34 vmonitor ntpd: kernel time sync status 0040 ::: ntpd:
Apr 11 16:51:34 vmonitor ntpd: kernel time sync status 0040 ::: ntpd: kernel time sync
Ce qui est normal puisque ntpd: qui est en début de fichier .conf se trouve aussi dans les lignes suprimées
Quand j'ai écrit le code je me suis limité à ta demande.
Voici pour tester
#!/usr/bin/perl use strict;use warnings; open CONF,"fichier.conf" or die "E/S : $!\n"; open ANALYSE,"fichier.analyse" or die "E/S : $!\n"; open TMP,">fichier.tmp" or die "E/S : $!\n"; open DEBUG,">debug.log" or die "E/S : $!\n"; my @conf=<CONF>; chomp @conf; while(my $e=<ANALYSE>){ chomp($e); print TMP $e,"\n" unless grep { if($_=~/\|/){ my ($x,$y)=split /\|/,$_; $y=~s/^\s*(.*)/$1/; print DEBUG "$e ::: $_\n" if $e=~/${x}.*$y/; }else{ print DEBUG "$e ::: $_\n" if $e=~/$_/; } } @conf; } __END__chez moi ça marche
Toutefois il y a des doublons
Apr 11 16:51:34 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123 ::: ntpd:
Apr 11 16:51:34 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123 ::: ntpd: Listening on
Apr 11 16:51:34 vmonitor ntpd: Listening on interface eth0, 172.16.15.39#123 ::: ntpd:
Apr 11 16:51:34 vmonitor ntpd: Listening on interface eth0, 172.16.15.39#123 ::: ntpd: Listening on
Apr 11 16:51:34 vmonitor ntpd: kernel time sync status 0040 ::: ntpd:
Apr 11 16:51:34 vmonitor ntpd: kernel time sync status 0040 ::: ntpd: kernel time sync
Ce qui est normal puisque ntpd: qui est en début de fichier .conf se trouve aussi dans les lignes suprimées
pourquoi pour des mes lignes tu a des resultas différents?
Apr 11 16:51:34 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123 ::: ntpd: Apr 11 16:51:34 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123 ::: ntpd: Listening on
Apr 11 16:51:34 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123 ::: ntpd: Apr 11 16:51:34 vmonitor ntpd: Listening on interface lo, 127.0.0.1#123 ::: ntpd: Listening on
tu vois ce script marche par contre si avec logger je rajoute une ligne comme :
Apr 22 11:26:21 vmonitor ALLO: test
cela n'est pris en compte nulle part, ni dans tmp ni dans debug
Apr 22 11:26:21 vmonitor ALLO: test
cela n'est pris en compte nulle part, ni dans tmp ni dans debug
ecoute, je te l'ai déjà dit
le script fonctionne sur les fichier que tu m'as donnée
mais je te rappelle aussi que j'ai fait un copier / coller depuis le mail
en revanche chez toi le script ne fonctionne pas
donc on ne travaille pas sur les même fichiers
en ce cas j'ai besoin que tu me donne tes fichiers par pièce jointe et pas par copier/coller
le script fonctionne sur les fichier que tu m'as donnée
mais je te rappelle aussi que j'ai fait un copier / coller depuis le mail
en revanche chez toi le script ne fonctionne pas
donc on ne travaille pas sur les même fichiers
en ce cas j'ai besoin que tu me donne tes fichiers par pièce jointe et pas par copier/coller