Comparaison de 2 fichiers ou arborescence
Bonjour,
Je souhaiterais comparer 2 fichiers qui peuvent éventuellement contenir des sous-répertoires.
Pour cela je liste dans un fichier (via un script) tous les chemins absolus avec la taille du fichier final en colonne 2.
Code:
1 2 3 4 5 6 7 8 9 10 11
|
SERVER1:kevin:/home/kevin>tree -s rep1
rep1
|-- [ 4096] rep11
| |-- [ 104] brian
| |-- [ 26] dady
| `-- [ 90] jon
|-- [ 4096] rep12
| `-- [ 26] papa
|-- [ 10] tata
`-- [ 19] tutu |
Code:
1 2
| SERVER1:kevin:/home/kevin>ls rep1
rep11 rep12 tata tutu |
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| SERVER1:kevin:/home/kevin>tree -s rep2_ref
rep2_ref
|-- [ 4096] rep21
| `-- [ 4096] rep211
| |-- [ 63] monica
| `-- [ 75] santa
|-- [ 4096] rep22
| |-- [ 50] file22_1
| `-- [ 15] file22_2
|-- [ 4096] rep23
|-- [ 10] tata
`-- [ 10] titi |
Code:
1 2
| SERVER1:kevin:/home/kevin>ls rep2_ref/
rep21 rep22 rep23 tata titi |
Dans mes 2 fichiers plats obtenus :
Code:
1 2 3 4 5 6 7
| SERVER1:kevin:/home/kevin>cat LISTE_rep1
/home/kevin/rep1/tata 10
/home/kevin/rep1/tutu 19
/home/kevin/rep1/rep12/papa 26
/home/kevin/rep1/rep11/jon 90
/home/kevin/rep1/rep11/dady 26
/home/kevin/rep1/rep11/brian 104 |
Code:
1 2 3 4 5 6 7 8
|
SERVER1:kevin:/home/kevin>cat LISTE_rep2_ref
/home/kevin/rep2_ref/rep22/file22_2 15
/home/kevin/rep2_ref/rep22/file22_1 50
/home/kevin/rep2_ref/tata 10
/home/kevin/rep2_ref/rep21/rep211/santa 75
/home/kevin/rep2_ref/rep21/rep211/monica 63
/home/kevin/rep2_ref/titi 10 |
Jusque là tout va bien.
Seconde étape :
Si me fixe rep2_ref comme référence, je voudrais faire ressortir dans un fichier "difference_file.txt" tout ce qui est dans rep2_ref mais pas dans rep1 :
Pour cela j'utilise le code suivant :
Code:
awk 'NR==FNR {t[$0]++; next} !t[$0]' /home/kevin/LISTE_rep1 /home/kevin/LISTE_rep2_ref > /home/kevin/difference_file.txt
Résultat dans le fichier difference_file.txt :
Code:
1 2 3 4 5 6 7
|
/home/kevin/rep2_ref/rep22/file22_2 15
/home/kevin/rep2_ref/rep22/file22_1 50
/home/kevin/rep2_ref/tata 10
/home/kevin/rep2_ref/rep21/rep211/santa 75
/home/kevin/rep2_ref/rep21/rep211/monica 63
/home/kevin/rep2_ref/titi 10 |
A première vue je ne comprends pas pourquoi on trouve le fichier tata dans le résultat difference_file.txt alors qu'il se trouve dans les 2 dossiers et qu'il a la même taille. Il ne devrait pas ressortir.
En revanche le fichier tutu est dans rep1 mais ne ressort pas dans difference_file.txt et cela me va bien car il ne figure pas dans rep2_ref.
Je rame là-dessus depuis des heures, impossible de trouver pourquoi je retrouve tata alors qu'il n'a rien à faire dans difference_file.txt .
C'est peut-être le code :
Code:
awk 'NR==FNR {t[$0]++; next} !t[$0]'
qui comporte quelque chose qui ne va pas……………………………. je ne vois pas du tout.