[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [linux] insertion automatique d'une ligne dans un texte



> encore une question à laquelle je ne sais pas répondre :
> j'ai un fichier de 65000 lignes.
> je veux ajouter une ligne (toujours la même) toutes les 100 lignes, jusqu'à la
> fin du document.

#!/usr/bin/perl
$i=0;
while (<>) {
  print $_;
  $i++;
  if ($i == 100) {
    # ici, affiche ta ligne:
    print "xxx xxx xxx\n";
    $i = 0;
  }
}

sauve-ça dans un script, puis
lescript < fichier_original > nouveau_fichier

Ou bien avec awk:
awk 'BEGIN{i=0}{print $0; i++; if (i==100){i=0; print "xxx xxx";}}' \
< fichier_original > nouveau_fichier

--
  -o) / Pascal Bleser                   ATOS Origin|
  /\\ \ e-Business Platform         Aachen, Germany|
 _\_v  \<guru@linuxbe.org> <pbleser@atosorigin.com>|
---------------------------------------------------|
Jesus saves, but Buddha makes incremental backups  :
---------------------------------------------------'

[ Soyez précis dans vos sujets svp afin de déterminer directement  ]
[ le type de demande...                                            ]
[ Pour vous (dés)inscrire, aller sur http://linuxbe.org/ml.php     ]
[ http://LinuxBe.org              Contact: listmaster@linuxbe.org  ]