<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Programmation on Leslamas</title><link>https://www.leslamas.net/tags/programmation/</link><description>Recent content in Programmation on Leslamas</description><generator>Hugo</generator><language>fr</language><lastBuildDate>Thu, 09 Feb 2017 14:14:47 +0100</lastBuildDate><atom:link href="https://www.leslamas.net/tags/programmation/index.xml" rel="self" type="application/rss+xml"/><item><title>Script Bash pour afficher un arbre</title><link>https://www.leslamas.net/post/script-bash-pour-afficher-un-arbre/</link><pubDate>Thu, 23 Apr 2015 10:22:00 +0200</pubDate><guid>https://www.leslamas.net/post/script-bash-pour-afficher-un-arbre/</guid><description>&lt;p&gt;Voici un petit script permettant de présenter sous forme d&amp;rsquo;arbre un fichier CSV sous la forme : &lt;em&gt;enfant;parent&lt;/em&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;
#!/bin/bash
currentlevel=0
root=&amp;#39;Vertébrés&amp;#39;
echo $root
# Affiche un arbre à partir du noeud passé en argument
function subtree
{
while IFS=&amp;#34;;&amp;#34; read enfant parent
do
#echo &amp;#34;test $enfant ; $parent&amp;#34;
if [ &amp;#34;$parent&amp;#34; == &amp;#34;$1&amp;#34; ] # Cherche et affiche les enfants du noeud actuel
then
for (( i=0; i&amp;lt;$currentlevel; i++ ))
do
echo -e -n &amp;#34;| &amp;#34;
done
echo -e &amp;#34;└------$enfant&amp;#34;
currentlevel=$((currentlevel+1))
subtree $enfant
currentlevel=$((currentlevel-1))
fi
done &amp;lt; animaux.csv
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Exemple de fichier en entrée :&lt;/p&gt;</description></item></channel></rss>