Concatener deux infos sur une même ligne

Résolu/Fermé
Ka-El Messages postés 260 Date d'inscription lundi 28 novembre 2011 Statut Membre Dernière intervention 7 août 2020 - 8 déc. 2016 à 11:12
Ka-El Messages postés 260 Date d'inscription lundi 28 novembre 2011 Statut Membre Dernière intervention 7 août 2020 - 8 déc. 2016 à 16:26
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 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
8 déc. 2016 à 12:03
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 lundi 2 mai 2016 Statut Contributeur Dernière intervention 22 décembre 2020 157
8 déc. 2016 à 11:43
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 lundi 2 mai 2016 Statut Contributeur Dernière intervention 22 décembre 2020 157
8 déc. 2016 à 12:14
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 lundi 28 novembre 2011 Statut Membre Dernière intervention 7 août 2020
8 déc. 2016 à 13:28
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 lundi 2 mai 2016 Statut Contributeur Dernière intervention 22 décembre 2020 157
8 déc. 2016 à 14:26
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 lundi 28 novembre 2011 Statut Membre Dernière intervention 7 août 2020
8 déc. 2016 à 16:26
Merci beaucoup pour ton aide UnGnU
ça fonctionne très bien.
Je ferme le sujet.
@+
0