Concatener deux infos sur une même ligne

Résolu
Ka-El Messages postés 260 Date d'inscription   Statut Membre Dernière intervention   -  
Ka-El Messages postés 260 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
Je tente en vain de créer un fichier vers lequel je souhaite concaténer 2 informations distinctes sur une même ligne.
Voici le contenu de mon fichier source "toto.txt" :
-rw-rw-r-- 1 toto groland 2344 Oct 10 16:38 /toto/groland/tmp/F0378600
-rw-rw-r-- 1 toto groland 60500800 Oct 10 16:57 /toto/groland/tmp/F0378709
-rw-rw-r-- 1 toto groland 60500840 Oct 10 16:57 /toto/groland/tmp/F0378709.pi99
-rw-rw-r-- 1 toto groland 1824 Oct 10 17:53 /toto/groland/tmp/F0378744
-rw-rw-r-- 1 toto groland 2084 Oct 11 00:39 /toto/groland/tmp/F0378929

j'ai imaginé cette commande, mais je n'obtiens pas du tout le résultat attendu:
while read line
do
Num=`echo -e "$line" | grep -o 'F[0-9]*' | cut -c 2-`
echo $Num $line >> resultat.txt
done < toto.txt

Au final, je souhaiterais obtenir le fichier "resultat.txt" suivant:
-rw-rw-r-- 1 toto groland 2344 Oct 10 16:38 /toto/groland/tmp/F0378600 0378600
-rw-rw-r-- 1 toto groland 60500800 Oct 10 16:57 /toto/groland/tmp/F0378709 0378709
-rw-rw-r-- 1 toto groland 60500840 Oct 10 16:57 /toto/groland/tmp/F0378709.pi99 0378709
-rw-rw-r-- 1 toto groland 1824 Oct 10 17:53 /toto/groland/tmp/F0378744 0378744
-rw-rw-r-- 1 toto groland 2084 Oct 11 00:39 /toto/groland/tmp/F0378929 0378929

Merci d'avance pour votre aide !
Ka-El
A voir également:

5 réponses

dubcek Messages postés 18789 Date d'inscription   Statut Contributeur Dernière intervention   5 636
 
hello
$ awk -F "F|[.]" '{print $0, $2}' toto.txt
-rw-rw-r-- 1 toto groland 2344 Oct 10 16:38 /toto/groland/tmp/F0378600 0378600
-rw-rw-r-- 1 toto groland 60500800 Oct 10 16:57 /toto/groland/tmp/F0378709 0378709
-rw-rw-r-- 1 toto groland 60500840 Oct 10 16:57 /toto/groland/tmp/F0378709.pi99 0378709
-rw-rw-r-- 1 toto groland 1824 Oct 10 17:53 /toto/groland/tmp/F0378744 0378744
-rw-rw-r-- 1 toto groland 2084 Oct 11 00:39 /toto/groland/tmp/F0378929 0378929
1
UnGnU Messages postés 1158 Date d'inscription   Statut Contributeur Dernière intervention   158
 
Salut,

$ cat fich
-rw-rw-r-- 1 toto groland 2344 Oct 10 16:38 /toto/groland/tmp/F0378600
-rw-rw-r-- 1 toto groland 60500800 Oct 10 16:57 /toto/groland/tmp/F0378709
-rw-rw-r-- 1 toto groland 60500840 Oct 10 16:57 /toto/groland/tmp/F0378709.pi99
-rw-rw-r-- 1 toto groland 1824 Oct 10 17:53 /toto/groland/tmp/F0378744
-rw-rw-r-- 1 toto groland 2084 Oct 11 00:39 /toto/groland/tmp/F0378929


$ sed 's/\(.*F\)\([^.]*\)\(.*\)/\1\2\3 \2/' fich
-rw-rw-r-- 1 toto groland 2344 Oct 10 16:38 /toto/groland/tmp/F0378600 0378600
-rw-rw-r-- 1 toto groland 60500800 Oct 10 16:57 /toto/groland/tmp/F0378709 0378709
-rw-rw-r-- 1 toto groland 60500840 Oct 10 16:57 /toto/groland/tmp/F0378709.pi99 0378709
-rw-rw-r-- 1 toto groland 1824 Oct 10 17:53 /toto/groland/tmp/F0378744 0378744
-rw-rw-r-- 1 toto groland 2084 Oct 11 00:39 /toto/groland/tmp/F0378929 0378929

0
UnGnU Messages postés 1158 Date d'inscription   Statut Contributeur Dernière intervention   158
 
Re-

Si tu tiens absolument à le faire en shell bash :

#!/bin/bash

while read line
do
 A="${line#*F}"
 B="${A%.*}"
 echo "${line} ${B}"
done < fichier

0
Ka-El Messages postés 260 Date d'inscription   Statut Membre Dernière intervention  
 
Bonjour et merci Ungnu,
Je crois qu'il me faut effectivement ce type de shell pour arriver à mes fins.
je vais tester ça.
merci beaucoup !
0
UnGnU Messages postés 1158 Date d'inscription   Statut Contributeur Dernière intervention   158
 
Juste pour le fun ;-))

paste -d " " fichier <(grep -Po '.*F\K[^.]*|$' fichier)

0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Ka-El Messages postés 260 Date d'inscription   Statut Membre Dernière intervention  
 
Merci beaucoup pour ton aide UnGnU
ça fonctionne très bien.
Je ferme le sujet.
@+
0