Lire des fichier dans un repertoire en perl
Fermé
Kadavra
-
25 févr. 2010 à 13:50
lami20j Messages postés 21331 Date d'inscription jeudi 4 novembre 2004 Statut Modérateur, Contributeur sécurité Dernière intervention 30 octobre 2019 - 25 févr. 2010 à 16:48
lami20j Messages postés 21331 Date d'inscription jeudi 4 novembre 2004 Statut Modérateur, Contributeur sécurité Dernière intervention 30 octobre 2019 - 25 févr. 2010 à 16:48
A voir également:
- Lire des fichier dans un repertoire en perl
- Lire le coran en français pdf - Télécharger - Histoire & Religion
- Lire fichier epub - Guide
- Lire fichier bin - Guide
- Fichier rar - Guide
- Comment réduire la taille d'un fichier - Guide
1 réponse
lami20j
Messages postés
21331
Date d'inscription
jeudi 4 novembre 2004
Statut
Modérateur, Contributeur sécurité
Dernière intervention
30 octobre 2019
3 569
25 févr. 2010 à 16:48
25 févr. 2010 à 16:48
Salut,
Voici un script qui lit tous les fichiers .txt d'un répertoire et il affiche le nom de fichier (arborescence complète) et le nombre de lignes de chaque fichier.
Voici un script qui lit tous les fichiers .txt d'un répertoire et il affiche le nom de fichier (arborescence complète) et le nombre de lignes de chaque fichier.
#!/usr/bin/perl use strict;use warnings; my %h; my $rep = "/home/lami20j"; opendir(REP,$rep) or die "E/S : $!\n"; while(defined(my $fic=readdir REP)){ my $f="${rep}/$fic"; if($fic=~/.*\.txt/){ open FIC, "$f" or warn "$f E/S: $!\n"; while(<FIC>){} $h{$f}=$.; close FIC; } } printf "%-35s - $h{$_} ligne(s)\n",$_ for sort keys %h; __END__Le résultat
lami20j@debian:~$ perl nombrelignes.pl /home/lami20j/a.txt - 5 ligne(s) /home/lami20j/aa.txt - 1 ligne(s) /home/lami20j/adresses.txt - 2 ligne(s) /home/lami20j/awk.txt - 3 ligne(s) /home/lami20j/b.txt - 5 ligne(s) /home/lami20j/c.txt - 5 ligne(s) /home/lami20j/cp.txt - 15 ligne(s) /home/lami20j/dtd.txt - 10 ligne(s) /home/lami20j/ecrire.txt - 3 ligne(s) /home/lami20j/fdisk.txt - 15 ligne(s) /home/lami20j/fic.txt - 3 ligne(s) /home/lami20j/fic1.txt - 5 ligne(s) /home/lami20j/fic2.txt - 7 ligne(s) /home/lami20j/fich.txt - 2 ligne(s) /home/lami20j/fichier.txt - 3 ligne(s) /home/lami20j/fichier1.txt - 1 ligne(s) /home/lami20j/fichier2.txt - 11 ligne(s) /home/lami20j/fichier3.txt - 1 ligne(s) /home/lami20j/fichier4.txt - 1 ligne(s) /home/lami20j/fichier5.txt - 1 ligne(s) /home/lami20j/fichier_1.txt - 3 ligne(s) /home/lami20j/fichier_2.txt - 3 ligne(s) /home/lami20j/fichier_3.txt - 3 ligne(s) /home/lami20j/fichier_4.txt - 3 ligne(s) /home/lami20j/fichier_resultat.txt - 0 ligne(s) /home/lami20j/fichier_resultat2.txt - 17 ligne(s) /home/lami20j/fjoint.txt - 0 ligne(s) /home/lami20j/fr.txt.bak - 5 ligne(s) /home/lami20j/h.txt - 1825 ligne(s) /home/lami20j/hexa.txt - 103 ligne(s) /home/lami20j/iptables.start.txt - 31 ligne(s) /home/lami20j/iptables.stop.txt - 15 ligne(s) /home/lami20j/iptables.txt - 13 ligne(s) /home/lami20j/ligne.txt - 8 ligne(s) /home/lami20j/ligne0.txt - 7 ligne(s) /home/lami20j/lire.txt - 1 ligne(s) /home/lami20j/mail.txt - 6 ligne(s) /home/lami20j/monExemple.txt - 4 ligne(s) /home/lami20j/number.txt - 4 ligne(s) /home/lami20j/pagination.txt - 199 ligne(s) /home/lami20j/plop.txt - 14 ligne(s) /home/lami20j/regex.txt - 2 ligne(s) /home/lami20j/resultat.txt - 4 ligne(s) /home/lami20j/robot.txt - 4 ligne(s) /home/lami20j/sedaccents_html.txt - 5 ligne(s) /home/lami20j/t.txt - 10 ligne(s) /home/lami20j/target.txt - 6 ligne(s) /home/lami20j/text.txt - 18 ligne(s) /home/lami20j/texte.txt - 4 ligne(s) /home/lami20j/topic.txt - 66128 ligne(s) /home/lami20j/topic.txt.zip - 4310 ligne(s) /home/lami20j/topic_1.txt - 137676 ligne(s) /home/lami20j/tt.txt - 5 ligne(s) /home/lami20j/whatis.txt - 8548 ligne(s)