Pages : 1
#1 Le 27/02/2008, à 21:09
- yurek
récupéré un chemin formaté
je cherche depuis un bon moment mais je n'arrive pas a obtenir un chemin en le formatant avec sed ou awk cut...
bref j'ai un dossier photo ou il y a des photos plein de photos et je cherche a récupéré le chemin du dossier avec une selection des fichiers (zenity)
zenity me renvoi :
/home/moi/photo/salu.jpg (sachant que les noms changes)
et je cherche a récupéré /home/moi/photo uniquement
j'arrive a supprimer .jpg mais pas salu. n'y a t il pas une combinaison qui récupère toute la première partie jusqu'au dernier / .
http://doc.ubuntu-fr.org/installation/debutants
http://doc.ubuntu-fr.org/diagnostic
http://doc.ubuntu-fr.org/diagnostic_outils
http://doc.ubuntu-fr.org/reflexe_ubunteros
Hors ligne
#2 Le 27/02/2008, à 23:08
- i M@N
Re : récupéré un chemin formaté
Hello.
pwd = print working directory = affiche dossier courant
cd /home/user/dossier
dossier=`pwd`
echo $dossier #renvoie /home/user/dossier
@+...
1 x Intel(R) Core i7 2600K CPU 3.4GHz Debian sid = roxX !
1 x MSi Wind U100 Debian sid = roxX !!
Read The F***in' Manual or die tryin' !
webmaster @ http://www.rastavibes.net reggae shop
Hors ligne
#3 Le 28/02/2008, à 06:03
- frafa
Re : récupéré un chemin formaté
lo
t'as aussi
dirname "/home/ubuntu/Desktop/Hauppauge WinTV-NOVA-T - Stick"
==> /home/ubuntu/Desktop
basename "/home/ubuntu/Desktop/Hauppauge WinTV-NOVA-T - Stick"
==> Hauppauge WinTV-NOVA-T - Stick
Hors ligne
#4 Le 28/02/2008, à 13:08
- yurek
Re : récupéré un chemin formaté
vous comprenez pas. Zenity renvoi le chemin d'un fichier. C'est pas aussi simple
http://doc.ubuntu-fr.org/installation/debutants
http://doc.ubuntu-fr.org/diagnostic
http://doc.ubuntu-fr.org/diagnostic_outils
http://doc.ubuntu-fr.org/reflexe_ubunteros
Hors ligne
#5 Le 28/02/2008, à 13:17
- trucutu
Re : récupéré un chemin formaté
Ben, si tu veux traiter ensuite ce que te renvoi Zenity,
dirname /home/moi/photo/salu.jpg
où plutôt
PATH=dirname `zenity ... `
Me parais bon, non ?
La chanson du dimanche - "La pêche !"
PC acheté chez Novatux : entièrement satisfait.
Faire des recherches solidaires !
Hors ligne
#6 Le 28/02/2008, à 15:45
- Alain.g
Re : récupéré un chemin formaté
Salut
Pour sélectionner uniquement un dossier avec Zenity, on peut ajouter l'option "--directory"
zenity --file-selection --directory
Sinon pour supprimer le nom du fichier, soit "dirname" effectivement ou bien "${variable%/*}"
Dernière modification par Alain.g (Le 28/02/2008, à 15:45)
Xubuntu Karmic !
Hors ligne
#7 Le 28/02/2008, à 19:15
- yurek
Re : récupéré un chemin formaté
je vous adore merci.
Et sinon avec sed ce serai quoi la commande ?
http://doc.ubuntu-fr.org/installation/debutants
http://doc.ubuntu-fr.org/diagnostic
http://doc.ubuntu-fr.org/diagnostic_outils
http://doc.ubuntu-fr.org/reflexe_ubunteros
Hors ligne
#8 Le 28/02/2008, à 20:54
- Alain.g
Re : récupéré un chemin formaté
echo "$chemin" | sed 's,/[^/]\+$,,'
Xubuntu Karmic !
Hors ligne
#9 Le 28/02/2008, à 21:04
- yurek
Re : récupéré un chemin formaté
merci , j'essaye de comprendre mais je ne comprend pas les virgules, les $ les + bref une petite explication?
http://doc.ubuntu-fr.org/installation/debutants
http://doc.ubuntu-fr.org/diagnostic
http://doc.ubuntu-fr.org/diagnostic_outils
http://doc.ubuntu-fr.org/reflexe_ubunteros
Hors ligne
#10 Le 28/02/2008, à 22:53
- Alain.g
Re : récupéré un chemin formaté
la virgule joue ici le rôle de délimiteur (qui est habituellement un slash). On peut choisir un autre (#, | etc...). On évite de choisir un slash comme délimiteur pour ne pas devoir échapper ceux du motif.
[^/] correspond à tout caractère autre que le slash
le + (échappé, sauf avec l'option -r) est un quantificateur indiquant que ce qui précède (ici [^/]) apparaît une ou plusieurs fois de suite.
Je crois que + n'est utilisable qu'avec la version GNU de sed . Pour plus de compatibilité on peut utiliser * (sans l'échapper), qui signifie zéro, une ou plusieurs fois
$ correspond à la fin de ligne
On efface un slash suivi d'une suite de caractères autre qu'un slash se trouvant en fin de ligne.
Dernière modification par Alain.g (Le 28/02/2008, à 23:00)
Xubuntu Karmic !
Hors ligne
Pages : 1