AWK : créer des champs à partir d'un texte en colonne
Résolu
Bonjour,
J'ai un fichier texte qui se présente comme ceci :
etc...
et je souhaiterais, avec awk ou en shell, le transformer en :
etc...
Pouvez-vous m'aider ? Merci
J'ai un fichier texte qui se présente comme ceci :
date-1
nature-1
montant-1
date-2
nature-2
montant-2
date-3
nature-3
montant-3
etc...
et je souhaiterais, avec awk ou en shell, le transformer en :
date-1 ; nature-1 ; montant-1
date-2 ; nature-2 ; montant-2
date-3 ; nature-3 ; montant-3
etc...
Pouvez-vous m'aider ? Merci
2 réponses
-
Bonjour,
toto.txt
date-1
nature-1
montant-1
date-2
nature-2
montant-2
date-3
nature-3
montant-3
toto.awk
BEGIN { i = 0; s = ""; } { if (s) { s = s " ; " $0; } else { s = $0 } i += 1 if (i % 3 == 0) { print(s); s = ""; } }
Exécution
(mando@silk) (~) $ awk -f toto.awk toto.txt
date-1 ; nature-1 ; montant-1
date-2 ; nature-2 ; montant-2
date-3 ; nature-3 ; montant-3
Bonne chance -