Ajouter du texte une ligne sur cinq
Résolu
nohl
-
nohl -
nohl -
Bonjour,
J'ai une liste de mot dans un fichier, et j'ai besoin d'ajouter du texte contenue dans une variable toute les cinq lignes.
exemple :
$ cat fichier 1
toto
tata
tutu
momo
mama
mimi
titi
tuto
tati
fifi
riri
lulu
koko
pepe
et je voudrai en sorti :
*******
texte_en_plus1 : toto
tata
tutu
momo
mama
texte_en_plus2 : mimi
titi
tuto
tati
fifi
texte_en_plus3 : riri
lulu
koko
pepe
kuku
le texte en plus viens d'awk
qu'un aurait une idée??
j'ai trouvé sed -n 1~5p fichier pour retombé sur toutes les 5ligne d'un fichier...mais je bloque là
J'ai une liste de mot dans un fichier, et j'ai besoin d'ajouter du texte contenue dans une variable toute les cinq lignes.
exemple :
$ cat fichier 1
toto
tata
tutu
momo
mama
mimi
titi
tuto
tati
fifi
riri
lulu
koko
pepe
et je voudrai en sorti :
*******
texte_en_plus1 : toto
tata
tutu
momo
mama
texte_en_plus2 : mimi
titi
tuto
tati
fifi
texte_en_plus3 : riri
lulu
koko
pepe
kuku
le texte en plus viens d'awk
qu'un aurait une idée??
j'ai trouvé sed -n 1~5p fichier pour retombé sur toutes les 5ligne d'un fichier...mais je bloque là
4 réponses
-
Salut,
$ cat fich toto tata tutu momo mama mimi titi tuto tati fifi riri lulu koko pepe kuku $ echo $VAR texte_en_plus : $ sed -i.bak '1~5 s/.*/'"${VAR}"'&/' fich $ cat fich texte_en_plus : toto tata tutu momo mama texte_en_plus : mimi titi tuto tati fifi texte_en_plus : riri lulu koko pepe kuku
;-))
-
euh...perso, j'ai aucun changement. et un fichier .bak vide qui se créé.
ps : je suis sous bash -
en fait, c'est bon, je l'ai fait marcher.... seulement, j'ai oublier de te dire que mon "texte_en_plus" n'est jamais le même en fait ^^. c'est ça le problème
-
$ cat plop toto tata tutu momo mama mimi titi tuto tati fifi riri lulu koko pepe kuku $ cat fich texte_en_plus 1 : texte_en_plus 2 : texte_en_plus 3 : $ i=1; while read line; do sed -i "$i s/.*/${line} &/" plop;((i+=5));done < fich $ cat plop texte_en_plus 1 : toto tata tutu momo mama texte_en_plus 2 : mimi titi tuto tati fifi texte_en_plus 3 : riri lulu koko pepe kuku $
;-))