#1 Le 31/12/2019, à 16:30
- philoeil
[RESOLU] shell commande AWK retour de variable à zero, pourquoi ?
Bonjour,
Je ne comprends pas le retour de ma commande variable "NbDblonRep[Dblon] " à zero alors que précédemment la valeur est OK
Je ne comprends pas d'ailleurs pourquoi NbDblonRep[$1] s'affiche
En bref : pouvez-vous m'aider ?
L'extrait du code amenant le resultat :
echo "Ci-après la liste des noms des répertoires avec le nombre de doublons dans ce répertoire/nombre de fichiers présents "
awk -F' § ' 'BEGIN { print "Info3 : " }
{
if (/^\s*§+/) { next }
else
{ NomRep[$1]=$1; NbRepDbl[$1]+=1 }
{ NbDblonRep[$1]=(system("find " NomRep[$1] " -maxdepth 1 -type f | wc -l")) }
}
END {
for ( Dblon in NbRepDbl) {
printf("Repertoire doublon : %15s ===> %3d doublons sur %3s " , NomRep[Dblon] , NbRepDbl[Dblon] , NbDblonRep[Dblon] )
# ligne a supprimer: system("find " NomRep[Dblon] " -maxdepth 1 -type f | wc -l")
print("fichiers \n")
}
}' $REP
Le resultat inattendu :
Ci-après la liste des noms des répertoires avec le nombre de doublons dans ce répertoire/nombre de fichiers présents
Info3 :
10
2
11
2
11
10
11
10
11
10
11
10
11
2
11
10
11
10
11
10
2
11
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 ===> 8 doublons sur 0 fichiers
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 ===> 10 doublons sur 0 fichiers
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.1 ===> 2 doublons sur 0 fichiers
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.2 ===> 2 doublons sur 0 fichiers
Le fichier REP :
§§§§§§ Empreinte MD5 identique pour : 28a07d4c607ad7aee69583b110e3c6bf des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 § Elisa Vellia_Voleur de Secrets_02_Otan Harazi.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.1 § Rep2.1.Elisa Vellia_Voleur de Secrets_02_Otan Harazi.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Elisa Vellia_Voleur de Secrets_02_Otan Harazi.mp3
§§§§§§ Empreinte MD5 identique pour : 3681351dbd8aab4ae94b010c02f02cce des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.2 § Rep2.2.Platinum Collection Disc 1_01_Gabriel's Oboe.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Platinum Collection Disc 1_01_Gabriel's Oboe.mp3
§§§§§§ Empreinte MD5 identique pour : 415dcf8f85ce7a1b5e3a4583ef9863b0 des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 § Elisa Vellia_Voleur de Secrets_05_Le Guide des Étoiles.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Elisa Vellia_Voleur de Secrets_05_Le Guide des Étoiles.mp3
§§§§§§ Empreinte MD5 identique pour : 6a56c854a1f336468860bebc5033202b des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 § Elisa Vellia_Voleur de Secrets_04_Voleur de Secrets.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Elisa Vellia_Voleur de Secrets_04_Voleur de Secrets.mp3
§§§§§§ Empreinte MD5 identique pour : 874855a482ee84fe4a2163a6679dedf3 des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 § Elisa Vellia_Voleur de Secrets_06_Yar Ko Parag.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Elisa Vellia_Voleur de Secrets_06_Yar Ko Parag.mp3
§§§§§§ Empreinte MD5 identique pour : a13a85c3b31e4c6b21c6dfcd0afcc7f0 des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 § Elisa Vellia_Voleur de Secrets_08_Astrapse I Anatoli.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Elisa Vellia_Voleur de Secrets_08_Astrapse I Anatoli.mp3
§§§§§§ Empreinte MD5 identique pour : cb25a3284c67db9c42f42993e5bca369 des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.2 § Rep2.2.Platinum Collection Disc 1_02_Il Buono, Il Brutto, Il Cattivo.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Platinum Collection Disc 1_02_Il Buono, Il Brutto, Il Cattivo.mp3
§§§§§§ Empreinte MD5 identique pour : d17c9312f6b705f89ff4db625f379ac0 des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 § Elisa Vellia_Voleur de Secrets_03_Le Chant de Yestimani.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Elisa Vellia_Voleur de Secrets_03_Le Chant de Yestimani.mp3
§§§§§§ Empreinte MD5 identique pour : d3fad710647642c327aceeec1b773a71 des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 § Elisa Vellia_Voleur de Secrets_07_Valse du Printemps Égaré (Instrumental).mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Elisa Vellia_Voleur de Secrets_07_Valse du Printemps Égaré (Instrumental).mp3
§§§§§§ Empreinte MD5 identique pour : d6eb958ed7ab196838f32f1de0717d8c des fichiers suivants :
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 § Elisa Vellia_Voleur de Secrets_01_Ena Ohi.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.1 § Rep2.1.Elisa Vellia_Voleur de Secrets_01_Ena Ohi.mp3
/home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 § Rep2Elisa Vellia_Voleur de Secrets_01_Ena Ohi.mp3
Merci à toutes les bonnes volontés
Dernière modification par philoeil (Le 02/01/2020, à 08:48)
Hors ligne
#2 Le 31/12/2019, à 18:26
- kamaris
Re : [RESOLU] shell commande AWK retour de variable à zero, pourquoi ?
Tu ne captures pas la sortie de la commande find dans NbDblonRep[$1], mais son code retour.
Pour capturer la sortie, il faut utiliser getline :
"find " NomRep[$1] " -maxdepth 1 -type f | wc -l" | getline NbDblonRep[$1]
Hors ligne
#3 Le 31/12/2019, à 18:40
- pingouinux
Re : [RESOLU] shell commande AWK retour de variable à zero, pourquoi ?
Bonjour,
Dans awk, la commande system renvoie le code de retour de la commande (0 en cas de succès).
system(cmd-line) Execute the command cmd-line, and return the exit status. (This may
not be available on non-POSIX systems.)
Édité : Je me suis fait griller pendant que je rédigeais ma réponse.
Dernière modification par pingouinux (Le 31/12/2019, à 18:41)
Hors ligne
#4 Le 31/12/2019, à 19:18
- philoeil
Re : [RESOLU] shell commande AWK retour de variable à zero, pourquoi ?
Bonjour,
Merci beaucoup à vous pingoinux et Kamaris
MAis il y a encore un probleme
mon code corrigé
echo "Ci-après la liste des noms des répertoires avec le nombre de doublons dans ce répertoire/nombre de fichiers présents "
awk -F' § ' 'BEGIN { print "Info3 : " }
{
if (/^\s*§+/) { next }
else
{ NomRep[$1]=$1; NbRepDbl[$1]+=1}
{ NbDblonRep[$1]=(system("find " NomRep[$1] " -maxdepth 1 -type f | wc -l")) | getline NbDblonRep[$1]}
}
END {
for ( Dblon in NbRepDbl) {
printf("Repertoire doublon : %15s ===> %3d doublons sur %3s " , NomRep[Dblon] , NbRepDbl[Dblon] , NbDblonRep[Dblon] )
# ligne a supprimer: system("find " NomRep[Dblon] " -maxdepth 1 -type f | wc -l")
print("fichiers \n")
}
}' $REP
Le resultat
il y a "sh: 1: 0: not found"
et je ne récupère pas NbDblonRep[Dblon] avec la valeur attendue elle reste à zero
Ci-après la liste des noms des répertoires avec le nombre de doublons dans ce répertoire/nombre de fichiers présents
Info3 :
10
sh: 1: 0: not found
2
11
2
11
10
11
10
11
10
11
10
11
2
11
10
11
10
11
10
2
11
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 ===> 8 doublons sur 0 fichiers
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 ===> 10 doublons sur 0 fichiers
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.1 ===> 2 doublons sur 0 fichiers
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.2 ===> 2 doublons sur 0 fichiers
Je dois m'absenter mais je regarde vos réponses jeudi sans faute
MErci à vous
Hors ligne
#5 Le 31/12/2019, à 19:22
- kamaris
Re : [RESOLU] shell commande AWK retour de variable à zero, pourquoi ?
Jette un coup d'œil au manuel quand même, avant de recopier
La ligne que je t'ai donnée en #2 se suffit à elle-même, c'est-à-dire qu'elle remplace totalement la ligne
NbDblonRep[$1]=(system("find " NomRep[$1] " -maxdepth 1 -type f | wc -l"))
Hors ligne
#6 Le 01/01/2020, à 21:10
- philoeil
Re : [RESOLU] shell commande AWK retour de variable à zero, pourquoi ?
Bonjour,
Merci kamaris
J'avais essayé le poste #2 mais cela entrainait une erreur voir ci-dessous
echo "Ci-après la liste des noms des répertoires avec le nombre de doublons dans ce répertoire/nombre de fichiers présents "
awk -F' § ' 'BEGIN { print "Info3 : " }
{
if (/^\s*§+/) { next }
else
{ NomRep[$1]=$1; NbRepDbl[$1]+=1
find " NomRep[$1] " -maxdepth 1 -type f | wc -l" | getline NbDblonRep[$1]}
}
END {
for ( Dblon in NbRepDbl) {
printf("Repertoire doublon : %15s ===> %3d doublons sur %3s " , NomRep[Dblon] , NbRepDbl[Dblon] , NbDblonRep[Dblon] )
# ligne a supprimer: system("find " NomRep[Dblon] " -maxdepth 1 -type f | wc -l")
print("fichiers \n")
}
}' $REP
J'avais donc tenté de réparer en ajoutant system voir post #4
J'ai fait une nouvelle tentative (plus proche de ta ligne) infructueuse ci-dessous
LE code
echo "Ci-après la liste des noms des répertoires avec le nombre de doublons dans ce répertoire/nombre de fichiers présents "
awk -F' § ' 'BEGIN { print "Info3 : " }
{
if (/^\s*§+/) { next }
else
{ NomRep[$1]=$1; NbRepDbl[$1]+=1
system("find " NomRep[$1] " -maxdepth 1 -type f | wc -l") | getline NbDblonRep[$1]}
}
END {
for ( Dblon in NbRepDbl) {
printf("Repertoire doublon : %15s ===> %3d doublons sur %3s " , NomRep[Dblon] , NbRepDbl[Dblon] , NbDblonRep[Dblon] )
# ligne a supprimer: system("find " NomRep[Dblon] " -maxdepth 1 -type f | wc -l")
print("fichiers \n")
}
}' $REP
LE resultat :
Ci-après la liste des noms des répertoires avec le nombre de doublons dans ce répertoire/nombre de fichiers présents
Info3 :
10
sh: 1: 0: not found
2
11
2
11
10
11
10
11
10
11
10
11
2
11
10
11
10
11
10
2
11
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep1 ===> 8 doublons sur fichiers
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2 ===> 10 doublons sur fichiers
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.1 ===> 2 doublons sur fichiers
Repertoire doublon : /home/phil/Documents/JeCodeShell/ShellEssaiRepDblons/Racine/Rep2/Rep2.2 ===> 2 doublons sur fichiers
Il ne reste donc plus que ces 2 points que je ne parviens pas à résoudre :
il y a l'info bizar : "sh: 1: 0: not found"
et je ne récupère pas NbDblonRep[Dblon] avec la valeur attendue (l'espace du rendu de la valeur n'est plus à zero mais est vide)
Merci pour ton aide
Hors ligne
#7 Le 01/01/2020, à 21:14
- kamaris
Re : [RESOLU] shell commande AWK retour de variable à zero, pourquoi ?
Tu as oublié un guillemet double dans ta première tentative : tu as mis
find " NomRep[$1] " -maxdepth 1 -type f | wc -l" | getline NbDblonRep[$1]}
alors que c'est
"find " NomRep[$1] " -maxdepth 1 -type f | wc -l" | getline NbDblonRep[$1]}
Hors ligne
#8 Le 02/01/2020, à 08:47
- philoeil
Re : [RESOLU] shell commande AWK retour de variable à zero, pourquoi ?
Bonjour,
Total respect Kamaris !
C'est RESOLU
Merci bien
Hors ligne