<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://forum.ubuntu-fr.org/extern.php?action=feed&amp;tid=1065721&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Forum Ubuntu-fr.org / encore du sed et awk]]></title>
		<link>http://forum.ubuntu-fr.org/viewtopic.php?id=1065721</link>
		<description><![CDATA[Les sujets les plus récents dans encore du sed et awk.]]></description>
		<lastBuildDate>Mon, 22 Oct 2012 06:48:46 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11210861#p11210861</link>
			<description><![CDATA[<p>merci beaucoup pour ces commandes <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Je n&#039;arrive vraiment pas à saisir awk, ca me semble tellement compliqué...</p><p>Oui j&#039;ai testé debchange, mais le soucis c&#039;est que si tu veux ajouter 25 lignes ca te prends 7sec alors qu&#039;avec un awk ou des echos, ca va bcp plus vite et c&#039;est bien dommage !</p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Mon, 22 Oct 2012 06:48:46 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11210861#p11210861</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11209731#p11209731</link>
			<description><![CDATA[<p>J&#039;arrive un peu après la bataille mais voici quelques suggestions en awk (parce que <a href="./viewtopic.php?id=781721">awk c&#039;est fun</a>) :</p><p>Afficher le numéro de version de la première ligne contenant mkv-extractor-gui :</p><div class="codebox"><pre><code>awk &#039;/^mkv-extractor-gui/{print gensub(/[^ ]* \(([0-9.]+).*/,&quot;\\1&quot;, &quot;g&quot;) ; exit}&#039; changelog</code></pre></div><br /><p>Récupérer le numéro de version dans la première ligne commençant par mkv-extractor-gui si disponible, sinon dans la première ligne commençant par poupou :</p><div class="codebox"><pre><code>awk &#039;/^mkv-extractor-gui/{if (! v1) {v1=gensub(/[^ ]* \(([0-9.]+).*/,&quot;\\1&quot;, &quot;g&quot;)}};/^poupou/{if (! v2) {v2=gensub(/[^ ]* \(([^~]+).*/,&quot;\\1&quot;, &quot;g&quot;)}} END {print (v1?&quot;version1 : &quot;v1:(v2?&quot;version2 : &quot;v2:&quot;Erreur, aucun numéro de version trouvé&quot;))}&#039; changelog</code></pre></div><br /><p>Récupérer le premier bloc commençant par mkv-extractor-gui :</p><div class="codebox"><pre><code>awk &#039;/^mkv-extractor-gui/{start++}; {if (start) {if (newline==2) {exit} ; if (!$0) {newline++} else {newline=0} ; print}}&#039; changelog</code></pre></div><p>ici j&#039;affiche le bloc au fur et à mesure, mais il va de soi que tu peux stocker les lignes dans un tableau et même les modifier. Avec mon exemple tu as 2 lignes vides à la fin mais si tu affiches le contenu de ton tableau dans le bloc « END {…} » tu peux facilement les supprimer.<br />Pour récupérer un bloc différent (ex. le second) il te suffit de changer le (start) en (start==2).<br />Pour remplacer les sauts de ligne par « @@ » il suffit également d&#039;ajouter « BEGIN{ORS=&quot;@@&quot;} » au début de la commande awk.</p><p>Une méthode plus compacte si tu désires juste faire de l&#039;affichage :</p><div class="codebox"><pre><code>awk &#039;BEGIN{RS=&quot;\n\n\n+&quot;} /^mkv-extractor-gui/{print;exit}&#039; changelog</code></pre></div><br /><p>Maintenant si tu veux remplacer spécifiquement ce bloc tout en gardant le reste :</p><div class="codebox"><pre><code>NOUVEAU_BLOC=&#039;nouveau bloc\n\n  * au milieu\n\n&#039;
awk &#039;/^mkv-extractor-gui/{start++}; {if (start &amp;&amp; newline&lt;2) {if (!$0) {newline++} else {newline=0} ; if (newline==2) {print &quot;&#039;&quot;${NOUVEAU_BLOC}&quot;&#039;&quot;; newline++}} else {print}}&#039; changelog</code></pre></div><p>une variante plus courte :</p><div class="codebox"><pre><code>NOUVEAU_BLOC=&#039;nouveau bloc\n\n  * au milieu&#039;
awk &#039;BEGIN{RS=&quot;\n\n\n+&quot;;ORS=&quot;\n\n\n&quot;} /^mkv-extractor-gui/{$0=(a++?$0:&quot;&#039;&quot;${NOUVEAU_BLOC}&quot;&#039;&quot;)};1&#039; changelog</code></pre></div><br /><p>Et si tu veux insérer ton nouveau bloc avant la première occurrence de ton bloc en mkv-extractor-gui (il y a plus simple si l&#039;on se contentait de trouver ce mot clé, mais ici ça vérifie que ce qui suit est bien un bloc. Voir l&#039;exemple suivant) :</p><div class="codebox"><pre><code>NOUVEAU_BLOC=&#039;nouveau bloc\n\n  * au milieu\n\n&#039;
awk &#039;/^mkv-extractor-gui/{start++}; {if (start &amp;&amp; newline&lt;2) {if (!$0) {newline++} else {newline=0} ; if (newline==2) {print &quot;&#039;&quot;${NOUVEAU_BLOC}&quot;&#039;&quot;; newline++ ; print bloc} ; bloc=bloc$0&quot;\n&quot;} else {print}}&#039; changelog</code></pre></div><p>Même chose sans vérifier que le bloc suit le format attendu :</p><div class="codebox"><pre><code>NOUVEAU_BLOC=&#039;nouveau bloc\n\n  * au milieu\n\n&#039;
awk &#039;/^mkv-extractor-gui/{start++;if (start==1) { print &quot;&#039;&quot;${NOUVEAU_BLOC}&quot;&#039;&quot;}}; {print}&#039; changelog</code></pre></div><p>une variante :</p><div class="codebox"><pre><code>NOUVEAU_BLOC=&#039;nouveau bloc\n\n  * au milieu\n\n&#039;
awk &#039;BEGIN{RS=&quot;\n\n\n+&quot;;ORS=&quot;\n\n\n&quot;} /^mkv-extractor-gui/{$0=(a++?&quot;&quot;:&quot;&#039;&quot;${NOUVEAU_BLOC}&quot;&#039;\n&quot;)$0};1&#039; changelog</code></pre></div><br /><p>Comme quoi awk c&#039;est vraiment génial <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /> non ?</p><p>NB. juste pour être plus sérieux je te signale aussi l&#039;existence de la commande <strong>debchange</strong> (et de son option -a) qui permet d&#039;éditer les fichiers de changelog <img src="http://forum.ubuntu-fr.org/img/smilies/tongue.png" width="15" height="15" alt="tongue" /></p>]]></description>
			<author><![CDATA[dummy@example.com (nesthib)]]></author>
			<pubDate>Sun, 21 Oct 2012 23:46:04 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11209731#p11209731</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11209061#p11209061</link>
			<description><![CDATA[<p>Bon j&#039;ai fait autrement car ca me derangait d&#039;obliger d&#039;utiliser python (et donc son installation) pour un logiciel tout en bash...</p><p>voila ma solution :</p><div class="codebox"><pre><code>nom_paquet=&quot;mkv-extractor-gui&quot;
tout=$(&lt; &quot;${changelog}&quot;)
tout_jusqua_mkv=&quot;${tout%%${nom_paquet}*}&quot;
tout_apres_mkv=&quot;${nom_paquet} ${tout#*${nom_paquet} }&quot;
tout_apres_mkv=&quot;${tout_apres_mkv#*$&#039;\n\n\n&#039;}&quot;

echo &quot;${tout_jusqua_mkv}mkv-extractor-gui blabla
  * blbabla
  * ...

${tout_apres_mkv}
&quot; &gt; &quot;${changelog}&quot;</code></pre></div><p>pas forcement tres rapide ou des plus simple, mais ca devrait marcher en se passant de python.</p><p>En tout cas, pingouinux, je te remercie ENORMEMENT pour le temps passé à me lire et à essayer de m&#039;aider !!!<br />Vraiment merci !</p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Sun, 21 Oct 2012 21:57:12 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11209061#p11209061</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11208751#p11208751</link>
			<description><![CDATA[<div class="codebox"><pre><code>$ cat remplacement.py
#! /usr/bin/python
# -*- coding: utf-8 -*-

import sys, re

with open(sys.argv[1],&#039;r&#039;) as f : txt=f.read()
mon_paquet=sys.argv[2]
mon_texte=sys.argv[3]

sys.stdout.write( re.sub(&#039;(?m)^%s.*\n\n(  \*.*\n)+\n --.*$&#039;%mon_paquet,mon_texte,txt,count=1) )</code></pre></div><p>Utilisation :</p><div class="codebox"><pre><code>./remplacement.py fichier mkv-extractor-gui &#039;Ligne n°1 de mon texte
Ligne n°2 de mon texte 
Ligne n°3 de mon texte&#039;</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (pingouinux)]]></author>
			<pubDate>Sun, 21 Oct 2012 21:23:46 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11208751#p11208751</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11208621#p11208621</link>
			<description><![CDATA[<p>le probleme c&#039;est que les variables mon_paquet et mon_texte change tout le temps....</p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Sun, 21 Oct 2012 21:15:22 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11208621#p11208621</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11208381#p11208381</link>
			<description><![CDATA[<p>Bonsoir,<br />Une solution en <strong>python</strong> :</p><div class="codebox"><pre><code>$ cat remplacement.py
#! /usr/bin/python
# -*- coding: utf-8 -*-

import sys, re

mon_paquet=&#039;mkv-extractor-gui&#039;
mon_texte=&#039;&#039;&#039;Ligne n°1 de mon texte
Ligne n°2 de mon texte 
Ligne n°3 de mon texte&#039;&#039;&#039;

with open(sys.argv[1],&#039;r&#039;) as f : txt=f.read()

sys.stdout.write( re.sub(&#039;(?m)^%s.*\n\n(  \*.*\n)+\n --.*$&#039;%mon_paquet,mon_texte,txt,count=1) )</code></pre></div><p>Utilisation :</p><div class="codebox"><pre><code>./remplacement.py fichier</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (pingouinux)]]></author>
			<pubDate>Sun, 21 Oct 2012 20:56:43 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11208381#p11208381</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11201831#p11201831</link>
			<description><![CDATA[<p>arf !</p><p>il me faut encore modifier le code <img src="http://forum.ubuntu-fr.org/img/smilies/tongue.png" width="15" height="15" alt="tongue" /></p><p>Il me faut donc toujours rechercher un bloc a partir d&#039;un nom, mais le rempacement ne doit pas se limiter au texte etoilé mais à tout le bloc.</p><p>Donc, si je cherche mkv-extractor-gui :</p><div class="codebox"><pre><code>mkv-extractor-gui (4.8.0~ppa1~lucid) lucid; urgency=low ()

  * Ajout des dépendances python-webkit imagemagick mclean mkvalidator
  * Suppression du systray qui en prévision du passage a gtk3
  * Mise à jour de glade2script
  * Mise à jour du système de préférence
  * Remise en place du service menu ou du script nautilus
  * Et d&#039;autres choses...

 -- Belleguic Terence &lt;hizo@free.fr&gt;  Tue, 24 Jul 2012 00:35:07 +0200</code></pre></div><p>Désolé et merci <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Sun, 21 Oct 2012 13:10:55 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11201831#p11201831</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11123741#p11123741</link>
			<description><![CDATA[<p>parfait !!</p><p>merci infiniment !</p><p>Il me manquait plus que ca pour terminer mon module <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Sun, 14 Oct 2012 19:17:48 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11123741#p11123741</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11115721#p11115721</link>
			<description><![CDATA[<p>Bonjour,</p><div class="quotebox"><cite>Hizoka #6 a écrit&#160;:</cite><blockquote><div><p>un awk qui me permettrait de changer le texte commencant par des etoiles avec un autres texte</p></div></blockquote></div><p>S&#039;agit-il de ce texte ?</p><div class="quotebox"><blockquote><div><p>Récupérer le texte commençant par des étoiles du 1er bloc de nom_paquet</p></div></blockquote></div><p>Si oui :</p><div class="codebox"><pre><code>nom_paquet=mkv-extractor-gui

mon_texte=&#039;Ligne n°1 de mon texte
Ligne n°2 de mon texte
Ligne n°3 de mon texte&#039;

awk -v mon_texte=&quot;$mon_texte&quot; &#039;{if(/^&#039;&quot;$nom_paquet&quot;&#039; /&amp;&amp;!deja){print;getline;print;ORS_=ORS;RS_=RS;ORS=RS=&quot;\n\n&quot;;getline;print mon_texte;deja=1;ORS=ORS_;RS=RS_}else{print}}&#039; fichier</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (pingouinux)]]></author>
			<pubDate>Sun, 14 Oct 2012 06:48:51 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11115721#p11115721</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11113621#p11113621</link>
			<description><![CDATA[<p>Un petit up <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>merci</p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Sat, 13 Oct 2012 20:15:00 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11113621#p11113621</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093711#p11093711</link>
			<description><![CDATA[<p>une derniere question,</p><p>un awk qui me permettrait de changer le texte commencant par des etoiles avec un autres texte ?</p><div class="codebox"><pre><code>awk -v OCC=1 -v var=&quot;${cacavar}&quot; &#039;BEGIN{ OLDRS=RS;RS=&quot;\n\n\n&quot; } NR==OCC {printf(&quot;%s\n\n\n&quot;,var);RS=OLDRS} NR!=OCC&#039; &quot;${changelog}&quot; &gt; &quot;${changelog}-new&quot;</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Fri, 12 Oct 2012 07:08:16 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093711#p11093711</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093691#p11093691</link>
			<description><![CDATA[<p>c&#039;est parfait !</p><p>merci beaucoup à toi !!</p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Fri, 12 Oct 2012 07:05:54 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093691#p11093691</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093651#p11093651</link>
			<description><![CDATA[<p>J&#039;ai complété ma réponse au moment où tu répondais.</p>]]></description>
			<author><![CDATA[dummy@example.com (pingouinux)]]></author>
			<pubDate>Fri, 12 Oct 2012 07:03:00 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093651#p11093651</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093631#p11093631</link>
			<description><![CDATA[<p>merci <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Fri, 12 Oct 2012 07:01:12 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093631#p11093631</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  encore du sed et awk]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093361#p11093361</link>
			<description><![CDATA[<p>Bonjour,</p><div class="quotebox"><blockquote><div><p>y a-t-il moyen de virer le head sans trop compliquer ?</p></div></blockquote></div><div class="codebox"><pre><code>sed -n &quot;/${nom_paquet}/ s/${nom_paquet} (\(.*\)~ppa.*/\1/p;T;q&quot; fichier</code></pre></div><p>S&#039;il n&#039;y a pas concordance : <strong>T</strong> envoie à la fin<br />Sinon, on quitte</p><div class="quotebox"><blockquote><div><p>Récupérer le texte commençant par des étoiles du 1er bloc de nom_paquet</p></div></blockquote></div><div class="codebox"><pre><code>awk &#039;/&#039;$nom_paquet&#039;/{getline;RS=&quot;\n\n&quot;;FS=&quot;\n&quot;;getline;{ for(i=1; i &lt; NF; i++) {printf substr($i,5)&quot;@@&quot;} printf substr($NF,5)&quot;\n&quot; }exit}&#039; fichier</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (pingouinux)]]></author>
			<pubDate>Fri, 12 Oct 2012 06:34:28 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11093361#p11093361</guid>
		</item>
	</channel>
</rss>
