Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[BASH] Ajouter 10 lignes vides toutes les 2 lignes (resolu)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
dapsaille
Advocate
Advocate


Joined: 02 Aug 2004
Posts: 2366
Location: Paris

PostPosted: Fri Mar 19, 2010 7:25 pm    Post subject: [BASH] Ajouter 10 lignes vides toutes les 2 lignes (resolu) Reply with quote

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
View user's profile Send private message
marmotton
n00b
n00b


Joined: 29 Oct 2007
Posts: 57
Location: Toulouse, France

PostPosted: Fri Mar 19, 2010 7:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
dapsaille
Advocate
Advocate


Joined: 02 Aug 2004
Posts: 2366
Location: Paris

PostPosted: Fri Mar 19, 2010 7:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
marmotton
n00b
n00b


Joined: 29 Oct 2007
Posts: 57
Location: Toulouse, France

PostPosted: Fri Mar 19, 2010 8:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1906
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Fri Mar 19, 2010 9:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
geekounet
Bodhisattva
Bodhisattva


Joined: 11 Oct 2004
Posts: 3772
Location: Wellington, Aotearoa

PostPosted: Fri Mar 19, 2010 11:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum