Extraire information dans fichier
Résolu
Ka-El
Messages postés
260
Date d'inscription
Statut
Membre
Dernière intervention
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour,
Je suis actuellement confronté à un problème d'extraction.
Voilà je dispose d'un fichier que j'appellerais "toto.txt".
Voici son contenu:
Start
Serveur=anonyme
1212596 816 -rw-rw-r-- 1 toto groland 829924 nov. 29 04:35 /data/xpl/tmp/F0413691
1212871 35184 -rw-rw-r-- 1 toto groland 35984440 nov. 6 00:03 /data/xpl/tmp/F0397858.pi99
1212859 58048 -rw-rw-r-- 1 toto groland 59373540 nov. 3 14:22 /data/xpl/tmp/F0396850.pi99
1212891 684 -rw-rw-r-- 1 toto groland 693250 nov. 11 04:10 /data/xpl/tmp/F0401716
1212814 35200 -rw-rw-r-- 1 toto groland 36003240 oct. 30 00:01 /data/xpl/tmp/F0394328.pi99
213009 4 -rw-rw-r-- 1 toto groland 1044 oct. 12 17:23 /data/xpl/tmp/F0381021
1212720 4 -rw-rw-r-- 1 toto groland 40 oct. 14 17:29 /data/xpl/tmp/F0383063
1212721 4 -rw-rw-r-- 1 toto groland 2344 oct. 10 15:23 /data/xpl/tmp/F0378393
1212564 632 -rw-rw-r-- 1 toto groland 641737 nov. 28 04:41 /data/xpl/tmp/F0412689
End
Il faut que je parvienne à extraire le numéro qui se trouve en fin de ligne derrière le "F*".
A noter la difficulté avec la ligne suivante (il peut y en avoir plusieurs):
1212814 35200 -rw-rw-r-- 1 toto groland 36003240 oct. 30 00:01 /data/xpl/tmp/F0394328.pi99
Comment puis-je effectuer cette opération ?
Avec une boucle for j'imagine ?
Merci d'avance pour votre aide.
Ka-El
Je suis actuellement confronté à un problème d'extraction.
Voilà je dispose d'un fichier que j'appellerais "toto.txt".
Voici son contenu:
Start
Serveur=anonyme
1212596 816 -rw-rw-r-- 1 toto groland 829924 nov. 29 04:35 /data/xpl/tmp/F0413691
1212871 35184 -rw-rw-r-- 1 toto groland 35984440 nov. 6 00:03 /data/xpl/tmp/F0397858.pi99
1212859 58048 -rw-rw-r-- 1 toto groland 59373540 nov. 3 14:22 /data/xpl/tmp/F0396850.pi99
1212891 684 -rw-rw-r-- 1 toto groland 693250 nov. 11 04:10 /data/xpl/tmp/F0401716
1212814 35200 -rw-rw-r-- 1 toto groland 36003240 oct. 30 00:01 /data/xpl/tmp/F0394328.pi99
213009 4 -rw-rw-r-- 1 toto groland 1044 oct. 12 17:23 /data/xpl/tmp/F0381021
1212720 4 -rw-rw-r-- 1 toto groland 40 oct. 14 17:29 /data/xpl/tmp/F0383063
1212721 4 -rw-rw-r-- 1 toto groland 2344 oct. 10 15:23 /data/xpl/tmp/F0378393
1212564 632 -rw-rw-r-- 1 toto groland 641737 nov. 28 04:41 /data/xpl/tmp/F0412689
End
Il faut que je parvienne à extraire le numéro qui se trouve en fin de ligne derrière le "F*".
A noter la difficulté avec la ligne suivante (il peut y en avoir plusieurs):
1212814 35200 -rw-rw-r-- 1 toto groland 36003240 oct. 30 00:01 /data/xpl/tmp/F0394328.pi99
Comment puis-je effectuer cette opération ?
Avec une boucle for j'imagine ?
Merci d'avance pour votre aide.
Ka-El
A voir également:
- Extraire information dans fichier
- Fichier bin - Guide
- Fichier epub - Guide
- Fichier rar - Guide
- Extraire une video youtube - Guide
- Comment réduire la taille d'un fichier - Guide
2 réponses
echo "$a" | sed -e 's/^.*F\(.*\)/\1/g' 0413691 0397858.pi99 0396850.pi99 0401716 0394328.pi99 0381021 0383063 0378393 0412689
avec $a qui contient le retour de ton ls -l
a="`ls -l`"
Salut,
$ grep -Po '.*F\K[^.]*' fich
0413691
0397858
0396850
0401716
0394328
0381021
0383063
0378393
0412689
Salut,
Je l'applique mal ?Faut croire ;-(
$ cat fichier
Start
Serveur=anonyme
1212596 816 -rw-rw-r-- 1 toto groland 829924 nov. 29 04:35 /data/xpl/tmp/F0413691
1212871 35184 -rw-rw-r-- 1 toto groland 35984440 nov. 6 00:03 /data/xpl/tmp/F0397858.pi99
1212859 58048 -rw-rw-r-- 1 toto groland 59373540 nov. 3 14:22 /data/xpl/tmp/F0396850.pi99
1212891 684 -rw-rw-r-- 1 toto groland 693250 nov. 11 04:10 /data/xpl/tmp/F0401716
1212814 35200 -rw-rw-r-- 1 toto groland 36003240 oct. 30 00:01 /data/xpl/tmp/F0394328.pi99
213009 4 -rw-rw-r-- 1 toto groland 1044 oct. 12 17:23 /data/xpl/tmp/F0381021
1212720 4 -rw-rw-r-- 1 toto groland 40 oct. 14 17:29 /data/xpl/tmp/F0383063
1212721 4 -rw-rw-r-- 1 toto groland 2344 oct. 10 15:23 /data/xpl/tmp/F0378393
1212564 632 -rw-rw-r-- 1 toto groland 641737 nov. 28 04:41 /data/xpl/tmp/F0412689
End
$ grep -Po '.*F\K[^.]*' fichier
0413691
0397858
0396850
0401716
0394328
0381021
0383063
0378393
0412689
c'est pas mal du tout. Par contre, il me faudrait le même résultat mais sans l'extension ".pi99" sur les 3 lignes.
Une idée ?
Merci
ou inclus dans le sed ..
Mais je ne comprends pas pourquoi tu utilises un echo, sachant que je dois extraire les informations à partir d'un fichier ?
Ne faudrait-il pas passer par un "cat" ?
Désolé je ne suis pas une flèche en shell...
Après effectivement si les lignes se trouvent dans un fichier ce sera cat fichier | sed (edit : ou sed 's...' fichier )
ça marche bien, mais je me suis aperçu que ta commande ne donnait pas le résultat attendu avec les lignes de ce type:
1212625 1252 -rw-rw-r-- 1 toto groland 1276099 déc. 5 04:12 /data/xpl/tmp/F0418293
Visiblement c'est les caractères exotiques du mois "déc" qui empêche le traitement de se faire correctement.
Comment peut-on faire pour gérer néanmoins cette ligne et récupérer le numéro "0418293" ?
Tu as une idée ?