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 -
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
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:
- Concatener deux infos sur une même ligne
- Concatener deux cellules excel - Guide
- Partager photos en ligne - Guide
- Comment faire deux colonnes sur word - Guide
- Mètre en ligne - Guide
- Deux compte whatsapp sur le même téléphone samsung - Guide
5 réponses
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
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
Re-
Si tu tiens absolument à le faire en shell bash :
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
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question