Concatener deux infos sur une même ligne

Résolu
Ka-El Messages postés 279 Statut Membre -  
Ka-El Messages postés 279 Statut Membre -
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

5 réponses

  1. dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   5 660
     
    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
  2. UnGnU Messages postés 1468 Statut Contributeur 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
  3. UnGnU Messages postés 1468 Statut Contributeur 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
    1. Ka-El Messages postés 279 Statut Membre
       
      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
  4. UnGnU Messages postés 1468 Statut Contributeur 158
     
    Juste pour le fun ;-))

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

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

    Posez votre question
  6. Ka-El Messages postés 279 Statut Membre
     
    Merci beaucoup pour ton aide UnGnU
    ça fonctionne très bien.
    Je ferme le sujet.
    @+
    0