View previous topic :: View next topic |
Author |
Message |
dapsaille Advocate
Joined: 02 Aug 2004 Posts: 2366 Location: Paris
|
Posted: Fri Mar 19, 2010 7:25 pm Post subject: [BASH] Ajouter 10 lignes vides toutes les 2 lignes (resolu) |
|
|
Salut à tous.
J'ai un fichier auquel je dois rajouter 10 lignes vides toutes les 2 lignes ..
Et bah voila ... je ne vois pas comment traiter cela ...
Any idea ?
EDIT = j'avais pas vu les nouveaux noms ... advocate .... héhé .. c'te blague .... poseur de questions de gland ouais ^^
Last edited by dapsaille on Fri Mar 19, 2010 7:52 pm; edited 1 time in total |
|
Back to top |
|
|
marmotton n00b
Joined: 29 Oct 2007 Posts: 57 Location: Toulouse, France
|
Posted: Fri Mar 19, 2010 7:46 pm Post subject: |
|
|
Avec Awk ?
Edit : Par exemple :
Code: |
BEGIN{
i=0;
}
{
i++;
print($0);
if(i%2==0){
for(j=0 ; j<10 ; j++)
print("\r\n");
}
}
|
|
|
Back to top |
|
|
dapsaille Advocate
Joined: 02 Aug 2004 Posts: 2366 Location: Paris
|
Posted: Fri Mar 19, 2010 7:51 pm Post subject: |
|
|
mais c'est merveilleux tout ça,
tu m'enlèves une sacrée épine du pied et je vais de ce pas noter cela sur mon cahier à commandes magiques ^^
merci beaucoup
EDIT = j<5 plutot ^^ |
|
Back to top |
|
|
marmotton n00b
Joined: 29 Oct 2007 Posts: 57 Location: Toulouse, France
|
Posted: Fri Mar 19, 2010 8:01 pm Post subject: |
|
|
Ah merde t'as raison le print de awk est plutôt un "printLine"
Donc j<10 avec print("") ou j<5 avec print("\r\n")
Merci du retour.... |
|
Back to top |
|
|
Magic Banana Veteran
Joined: 13 Dec 2005 Posts: 1912 Location: Belo Horizonte, Minas Gerais, Brasil
|
Posted: Fri Mar 19, 2010 9:22 pm Post subject: |
|
|
Juste pour signaler que le faire en Shell pur est, tout autant, un jeu d'enfant :
Code: | #!/bin/sh
if [ -z "$1" -o "$1" = "--help" -o "$1" = "-h" ]
then
echo "Usage: $0 file"
exit 64
fi
while read line
do
echo $line
if [ -z "$odd" ]
then
odd=t
else
odd=
echo "
"
fi
done < "$1" |
|
|
Back to top |
|
|
geekounet Bodhisattva
Joined: 11 Oct 2004 Posts: 3772
|
Posted: Fri Mar 19, 2010 11:29 pm Post subject: |
|
|
Sinon avec le sed GNU, tout simplement :
Code: | % sed '0~2 a\\n\n\n\n\n\n\n\n\n\n' ton_fichier |
0~2 = toutes les 2 lignes à partir de 0
a\ = append
Je ne sais pas le faire avec le sed POSIX par contre... |
|
Back to top |
|
|
|