Créer et récupérer des variables dans une boucle for
Bonjour,
Je souhaiterais faire une copie du contenu d'un ensemble de fichiers xml dont j'ai le chemin dans une liste externe dont voici un extrait :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| SVIE_1177_2015-09-23_V3/Entities/Entity25023.xml
SVIE_1177_2015-09-23_V3/Entities/Entity24969.xml
SVIE_1177_2015-09-23_V3/Entities/Entity24997.xml
SVIE_1119_2010-11-24_V3/Entities/Entity35210.xml
SVIE_1123_2011-03-23_V3/Entities/Entity35591.xml
SVIE_1134_2012-02-22_V3/Entities/Entity30487.xml
SVIE_1163_2014-07-23_V3/Entities/Entity25712.xml
SVIE_1163_2014-07-23_V3/Entities/Entity25807.xml
SVIE_1125_2011-05-25_V3/Entities/Entity35690.xml
SVIE_1122_2011-02-23_V3/Entities/Entity35479.xml
SVIE_1122_2011-02-23_V3/Entities/Entity35518.xml
SVIE_1165_2014-09-24_V3/Entities/Entity19361.xml |
Comme on peut le voir, ces fichiers d'origine sont dispatchés dans plusieurs dossiers et je souhaiterais les rassembler dans un même dossier mais en gardant leur nom (Entity35518.xml, Entity19361.xml ... sous un dossier "corpus")
J'ai réussi à extraire de cette liste les noms de fichier de destination :
Code:
1 2 3 4 5 6 7 8 9 10
| $ for line in $(cat chemin_raccourci_fichier_projet_MESH_ANATOMIE.txt);do echo $line|awk -F\/ '{print $3}';done
Entity25023.xml
Entity24969.xml
Entity24997.xml
Entity35210.xml
Entity35591.xml
Entity30487.xml
Entity25712.xml
Entity25807.xml
Entity35690.xml |
Mais au moment d'enregistrer ces noms dans une variable dont j'ai besoin pour créer les nouveaux fichiers, je me retrouve avec le même nom plusieurs fois :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| $ for line in $(cat chemin_raccourci_fichier_projet_MESH_ANATOMIE.txt);do variable=$(echo $line|awk -F\/ '{print $3}') echo $variable;done
Entity30284.xml
Entity30284.xml
Entity30284.xml
Entity30284.xml
Entity30284.xml
Entity30284.xml
Entity30284.xml
Entity30284.xml
Entity30284.xml
Entity30284.xml
Entity30284.xml |
D'ailleurs, si je mets un nom autre que "variable", le shell m'affiche des lignes vides...
Et du coup je ne peux pas faire ma copie du contenu des fichiers
C'est peut être une erreur de débutant mais là je seche...