View previous topic :: View next topic |
Author |
Message |
Trevoke Advocate
Joined: 04 Sep 2004 Posts: 4099 Location: NY, NY
|
Posted: Fri Sep 23, 2005 7:54 pm Post subject: [SED] syntaxe pour un remplacement.. (resolu) |
|
|
J'ai un fichier qui a du texte, separe par des sauts de lignes, et qui a aussi, entre chaque morceau de texte,
--saut de ligne--
--chiffre entre 01 et 81 (+ un point)--
--saut de ligne--
et je voudrais remplacer ces trois lignes par une seule ligne avec un '%' dessus (sans les apostrophes).
donc, euh ...
sed s/^$ .... A l'aide! _________________ Votre moment detente
What is the nature of conflict?
Last edited by Trevoke on Thu Sep 29, 2005 12:40 pm; edited 1 time in total |
|
Back to top |
|
|
naerex Guru
Joined: 02 Apr 2005 Posts: 316 Location: Paris, France
|
Posted: Fri Sep 23, 2005 8:03 pm Post subject: |
|
|
ouch ! j'espere qu'il n'y aura pas ça aux LPIC |
|
Back to top |
|
|
Trevoke Advocate
Joined: 04 Sep 2004 Posts: 4099 Location: NY, NY
|
Posted: Fri Sep 23, 2005 8:30 pm Post subject: |
|
|
Quote: | # sed script to delete a block if /regex/ matches inside it
:t
/^$/,/^$/ { # For each line between these block markers..
/^$/!{ # If we are not at the /end/ marker
$!{ # nor the last line of the file,
N; # add the Next line to the pattern space
bt
} # and branch (loop back) to the :t label.
} # This line matches the /end/ marker.
/[0-9]/c\
%; # If /regex/ matches, delete the block.
} # Otherwise, the block will be printed.
#---end of script--- |
J'ai trouve ca, mais je n'arrive pas a le faire marcher.
En fait le probleme c'est que pour moi, start et end c'est la meme chose : ^$, c'est-a-dire une ligne vide.
Encore une fois, euh.. a l'aide! _________________ Votre moment detente
What is the nature of conflict? |
|
Back to top |
|
|
scout Veteran
Joined: 08 Mar 2003 Posts: 1991 Location: France, Paris en Semaine / Metz le W-E
|
Posted: Fri Sep 23, 2005 8:39 pm Post subject: |
|
|
En dépannage:
Code: | > echo -e "a\nb\n\n10.\n\nc\nd"
a
b
10.
c
d
> echo -e "a\nb\n\n10.\n\nc\nd" | ruby -e 'puts $<.read.gsub(/\n\n\d+\.\n\n/m,"\n%\n")'
a
b
%
c
d |
si j'ai pas reposté le truc en sed ce soir c'est que j'ai pas trouvé.
[EDIT] truc en ruby corrigé après relecture de ton post
[EDIT2] Code: | sed '/^$/N; /^\n[[:digit:]]*\./N; /^\n[[:digit:]]*\.\n$/c%' |
à ne pas prendre pour argent comptant ...
PS: j'ai mis environ 20 fois moins de temps en ruby ...
[EDIT3]ruby rerecorrigé
[EDIT4] Trevoke wrote: | Apprends awk et sed.
Quand t'auras maitrise ca, *la* tu pourras passer a autre chose. |
_________________ http://petition.eurolinux.org/ - Petition against ePatents
L'essence de la finesse |
|
Back to top |
|
|
Trevoke Advocate
Joined: 04 Sep 2004 Posts: 4099 Location: NY, NY
|
Posted: Fri Sep 23, 2005 11:05 pm Post subject: |
|
|
Mais j'ai pas maitrise awk et sed moi
Enfin, pas encore. _________________ Votre moment detente
What is the nature of conflict? |
|
Back to top |
|
|
Trevoke Advocate
Joined: 04 Sep 2004 Posts: 4099 Location: NY, NY
|
Posted: Fri Sep 23, 2005 11:07 pm Post subject: |
|
|
Ton truc en ruby marche, mais pas ton truc sed... Alors pour le principe, c'est pas resolu.
Ceci dit, faut peut-etre que je me mette au ruby moi
bohaf, si, ca marche au moins au boulot, alors pouf, resolu. _________________ Votre moment detente
What is the nature of conflict? |
|
Back to top |
|
|
|
|
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
|
|