Ajouter du texte une ligne sur cinq

Résolu/Fermé
nohl - 7 déc. 2010 à 01:10
 nohl - 8 déc. 2010 à 21:56
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à

4 réponses

zipe31 Messages postés 36402 Date d'inscription dimanche 7 novembre 2010 Statut Contributeur Dernière intervention 27 janvier 2021 6 407
7 déc. 2010 à 07:41
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

;-))
0
euh...perso, j'ai aucun changement. et un fichier .bak vide qui se créé.

ps : je suis sous bash
0
zipe31 Messages postés 36402 Date d'inscription dimanche 7 novembre 2010 Statut Contributeur Dernière intervention 27 janvier 2021 6 407
7 déc. 2010 à 13:09
ps : je suis sous bash
Moi aussi et chez moi ça marche, preuve à l'appui ;-\

Sous quel système ?
Quelle distrib ?
0
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
0
zipe31 Messages postés 36402 Date d'inscription dimanche 7 novembre 2010 Statut Contributeur Dernière intervention 27 janvier 2021 6 407
8 déc. 2010 à 16:53
$ 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
$

;-))
0
merci bcp ;)
0