Ajouter du texte une ligne sur cinq

Résolu
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à

4 réponses

  1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 501
     
    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
  2. nohl
     
    euh...perso, j'ai aucun changement. et un fichier .bak vide qui se créé.

    ps : je suis sous bash
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 501
       
      ps : je suis sous bash
      Moi aussi et chez moi ça marche, preuve à l'appui ;-\

      Sous quel système ?
      Quelle distrib ?
      0
  3. nohl
     
    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
  4. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 501
     
    $ 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
    1. nohl
       
      merci bcp ;)
      0