<?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=362703&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Forum Ubuntu-fr.org / Une action en fonction de l'extension d'un fichier ?]]></title>
		<link>http://forum.ubuntu-fr.org/viewtopic.php?id=362703</link>
		<description><![CDATA[Les sujets les plus récents dans Une action en fonction de l'extension d'un fichier ?.]]></description>
		<lastBuildDate>Tue, 01 Dec 2009 15:50:05 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3109606#p3109606</link>
			<description><![CDATA[<p>fais le test <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><div class="codebox"><pre><code>i=&quot;mon.fichier.texte.txt&quot;
echo ${i##*.}</code></pre></div><p>Pour confirmer un peu ce que dis ansuz : http://forum.ubuntu-fr.org/viewtopic.php?id=359256</p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Tue, 01 Dec 2009 15:50:05 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3109606#p3109606</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3109076#p3109076</link>
			<description><![CDATA[<div class="quotebox"><cite>nesthib a écrit&#160;:</cite><blockquote><div><p>@AnsuzPeorth : corrige moi si je dis une bêtise mais =~ n&#039;est-il pas un opérateur de comparaison d&#039;expressions régulières?</p></div></blockquote></div><p>réguliere, rationnel...j&#039;m&#039;y perds la dedans.<br />Fais des test sur un gros fichier, tu verras une énorme différence de temps d&#039;execution entre l&#039;utilisation de egrep ou du tild.</p>]]></description>
			<author><![CDATA[dummy@example.com (AnsuzPeorth)]]></author>
			<pubDate>Tue, 01 Dec 2009 11:06:38 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3109076#p3109076</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3109001#p3109001</link>
			<description><![CDATA[<div class="quotebox"><cite>nesthib a écrit&#160;:</cite><blockquote><div><p><strong>${i##*.}</strong> supprime le motif <span class="bbu">le plus long</span> de la variable <strong>i</strong> qui corresponde à <strong>*.</strong> (soit n&#039;importe quoi suivi d&#039;un point).<br />cela te vire donc tout ce qui est avant l&#039;extension s&#039;il y en a une. Attention si tu as un fichier nommé juste <strong>txt</strong> par exemple, <strong>${i##*.}</strong> te retournera quand même txt</p></div></blockquote></div><p>Et dans le cas d&#039;un nom qui aurait plusieurs points ? mon.fichier.texte.txt par exemple ?</p>]]></description>
			<author><![CDATA[dummy@example.com (abelthorne)]]></author>
			<pubDate>Tue, 01 Dec 2009 10:27:30 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3109001#p3109001</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108991#p3108991</link>
			<description><![CDATA[<p><strong>${i##*.}</strong> supprime le motif <span class="bbu">le plus long</span> de la variable <strong>i</strong> qui corresponde à <strong>*.</strong> (soit n&#039;importe quoi suivi d&#039;un point).<br />cela te vire donc tout ce qui est avant l&#039;extension s&#039;il y en a une. Attention si tu as un fichier nommé juste <strong>txt</strong> par exemple, <strong>${i##*.}</strong> te retournera quand même txt (ce que ne fait pas ma solution ou celle d&#039;AnsuzPeorth)</p><p>le double point-virgule sert à signifier la fin des commandes pour un motif donné de case et le passage au test suivant (exemple, en non gras les commentaires)<br /> motif txt : <strong>txt) ma commande1 ; ma commande2 ; ma commande3 ;;</strong> ← fin des commandes on teste un autre motif<br /> motif truc ou bidule : <strong>truc|bidule) ma commande4 ; ma commande5 ; ma commande6;;</strong><br /> autre motif : <strong>*) ma commande7 ;;</strong></p>]]></description>
			<author><![CDATA[dummy@example.com (nesthib)]]></author>
			<pubDate>Tue, 01 Dec 2009 10:21:45 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108991#p3108991</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108941#p3108941</link>
			<description><![CDATA[<p>J&#039;aimerais quand même des explications sur la solution d&#039;Hizoka, vu que je n&#039;aime pas taper des commandes que je ne comprends pas. <img src="http://forum.ubuntu-fr.org/img/smilies/wink.png" width="15" height="15" alt="wink" /></p><p>Il y a deux choses qui m&#039;échappent :<br />- <strong>case &quot;${i##*.}&quot; in</strong> : que signifie &quot;${i##*.}&quot; ?<br />- pourquoi deux points-virgules à la fin de chaque cas ? Le premier termine la commande et le deuxième fait office de break ?</p>]]></description>
			<author><![CDATA[dummy@example.com (abelthorne)]]></author>
			<pubDate>Tue, 01 Dec 2009 09:51:42 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108941#p3108941</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108885#p3108885</link>
			<description><![CDATA[<p>dans ce cas prends la solution d&#039;Hizoka, c&#039;est la plus claire à relire si tu te replonges dans ton code dans plusieurs semaines <img src="http://forum.ubuntu-fr.org/img/smilies/wink.png" width="15" height="15" alt="wink" /><br />Avec case tu peux mettre plusieurs commandes à la suite séparées par des ; la fin des commandes est indiquée par ;;</p>]]></description>
			<author><![CDATA[dummy@example.com (nesthib)]]></author>
			<pubDate>Tue, 01 Dec 2009 09:11:25 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108885#p3108885</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108857#p3108857</link>
			<description><![CDATA[<p>Ouh là, ça commence à se compliquer tout ça. Mon script est juste un lanceur un peu spécial, il n&#039;a pas besoin d&#039;être optimisé à tout prix. <img src="http://forum.ubuntu-fr.org/img/smilies/lol.png" width="15" height="15" alt="lol" /></p>]]></description>
			<author><![CDATA[dummy@example.com (abelthorne)]]></author>
			<pubDate>Tue, 01 Dec 2009 08:46:44 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108857#p3108857</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108820#p3108820</link>
			<description><![CDATA[<p>@Hizoka : nickel, je pensais à un truc du genre! Il faudra que je me mette tous les opérateurs de substitution de texte dans les variables en tête <img src="http://forum.ubuntu-fr.org/img/smilies/wink.png" width="15" height="15" alt="wink" /></p><p>@AnsuzPeorth : corrige moi si je dis une bêtise mais =~ n&#039;est-il pas un opérateur de comparaison d&#039;expressions régulières?</p>]]></description>
			<author><![CDATA[dummy@example.com (nesthib)]]></author>
			<pubDate>Tue, 01 Dec 2009 08:09:38 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108820#p3108820</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108684#p3108684</link>
			<description><![CDATA[<p>Si tu as bcp de fichier à traiter, les ER sont plus lourde que la comparaison bash.<br />Tu pourrais faire comme ça (une possibilité parmis tant d&#039;autres):</p><div class="codebox"><pre><code>#! /bin/bash
while read ligne
do
[[ &quot;$ligne&quot; =~ \.txt ]] || [[ &quot;$ligne&quot; =~ \.sh ]] &amp;&amp; echo &quot;le fichier $ligne correspond&quot;
done &lt; &lt;(ls /home/user/truc)
exit</code></pre></div><p>Pour mettre plusieurs commande facilement si correspondance:</p><div class="codebox"><pre><code>#! /bin/bash
while read ligne
do
[[ &quot;$ligne&quot; =~ \.txt ]] || [[ &quot;$ligne&quot; =~ \.sh ]] &amp;&amp; {
echo &quot;le fichier $ligne correspond&quot;
autres commandes
}

done &lt; &lt;(ls /home/user/truc)
exit</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (AnsuzPeorth)]]></author>
			<pubDate>Tue, 01 Dec 2009 01:39:18 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108684#p3108684</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108546#p3108546</link>
			<description><![CDATA[<div class="codebox"><pre><code>for i in *
do
case &quot;${i##*.}&quot; in
txt) echo &quot;c&#039;est un txt&quot; ;;
doc|ods) echo &quot;c&#039;est un doc ou un ods&quot; ;;
*)  echo &quot;c&#039;est autre chose&quot; ;;
esac
done</code></pre></div><p>c&#039;est assez propre non ? <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>EDIT : modif de la ligne 5</p><p>Apres tu peux ajouter des vérifications, genre vérifier si c&#039;est un dossier par ex avant de traiter..</p>]]></description>
			<author><![CDATA[dummy@example.com (Hizoka)]]></author>
			<pubDate>Mon, 30 Nov 2009 23:28:06 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108546#p3108546</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108535#p3108535</link>
			<description><![CDATA[<div class="codebox"><pre><code>grep -q -e &#039;\.\(ini\|log\)$&#039; &lt;&lt;&lt;$i</code></pre></div><p>-e pour activer les expressions rationnelles (alors il faut changer 2-3 trucs : \. pour un point sinon . = n&#039;importe quel caractère, \| pour l&#039;opérateur OR et \( \) pour entourer les alternatives du OR)</p>]]></description>
			<author><![CDATA[dummy@example.com (nesthib)]]></author>
			<pubDate>Mon, 30 Nov 2009 23:23:52 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108535#p3108535</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108462#p3108462</link>
			<description><![CDATA[<p>Ok. Si je veux tester deux extensions (.ini et .log) en même temps, est-ce qu&#039;il faut que je fasse </p><div class="codebox"><pre><code>if grep -q &#039;.ini$&#039; || grep -q &#039;.log$&#039; &lt;&lt;&lt;$i</code></pre></div><p>ou </p><div class="codebox"><pre><code>if grep -q &#039;.ini$&#039; &lt;&lt;&lt;$i || grep -q &#039;.log$&#039; &lt;&lt;&lt;$i</code></pre></div><p>? ou encore autre chose ? (Je n&#039;ai plus du tout l&#039;habitude de faire des scripts bash.)</p>]]></description>
			<author><![CDATA[dummy@example.com (abelthorne)]]></author>
			<pubDate>Mon, 30 Nov 2009 22:52:43 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108462#p3108462</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108355#p3108355</link>
			<description><![CDATA[<p>ça redirige le contenu de la variable vers grep</p><p>avec ton [ `echo &quot;$i&quot; | awk -F . &#039;{print $NF}&#039;` = &quot;ini&quot; ] tu as un process pour [], un pour `` (sous-shell), un pour echo, un pour | (sous-shell), un pour awk</p><p>avec grep -q &#039;.txt$&#039; &lt;&lt;&lt;$i, la redirection n&#039;ouvre pas de nouveau sous-shell (à ma connaissance) et pas besoin de test car le if prend le code de retour de grep qui est 0 si grep trouve ce qu&#039;il veut (succès) et 1 sinon (échec). Au final un seul nouveau process, le grep<br />Après en cherchant un peu il y a peut être encore mieux</p>]]></description>
			<author><![CDATA[dummy@example.com (nesthib)]]></author>
			<pubDate>Mon, 30 Nov 2009 22:06:53 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108355#p3108355</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108313#p3108313</link>
			<description><![CDATA[<p>J&#039;ai modifié mon message au même moment avec une commande qui a l&#039;air de marcher. <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Par curiosité, à quoi sert le &lt;&lt;&lt; dans ta commande ?</p>]]></description>
			<author><![CDATA[dummy@example.com (abelthorne)]]></author>
			<pubDate>Mon, 30 Nov 2009 21:53:31 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108313#p3108313</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  Une action en fonction de l'extension d'un fichier ?]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108296#p3108296</link>
			<description><![CDATA[<p>y&#039;a beaucoup mieux mais pour te donner une piste</p><div class="codebox"><pre><code>for i in `ls folder`
do
  if grep -q &#039;.txt$&#039; &lt;&lt;&lt;$i
  then
    echo &quot;match $i&quot;
  fi
done</code></pre></div><p>tu peux remplacer les if par des case<br />tu peux également utiliser find avec l&#039;option --exec si tu n&#039;as qu&#039;une ou deux extensions à tester</p>]]></description>
			<author><![CDATA[dummy@example.com (nesthib)]]></author>
			<pubDate>Mon, 30 Nov 2009 21:49:41 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3108296#p3108296</guid>
		</item>
	</channel>
</rss>
