[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Script in bash



Farnis scripsit:
>Hi All,
>
>ho un problema. Ho una directory che contiene dei file in questo formato:
>
>Artista Uno - Disegno Uno.jpg
>Artista Uno - Disegno Due.jpg
>[...]
>$ARTISTA - $OPERA.jpg
>
>Vorrei realizzare uno script che operi su ogni file, ed estragga dal nome del
>file i campi $ARTISTA e $OPERA (per ogni file), perche' dovrei passare questi
>campi ad un altro programma.

In bash non ho idea di dove mettermi le mani:) Ma Perl è un'altra
cosa.....


Voilà:)

#-----cut-here------------------
#!/usr/bin/perl Esegue il comando definito dalla variabile $prog su
#$autore $opera ottenuti dai file della directory corrente.

$prog = "echo";
opendir (DIR,".") || die "Impossibile leggere la directory\n";
@files = readdir(DIR);
foreach (@files) {
  next if (!m/-/); #saltiamo i file che non contengono -, in
                   #particolare . e ..
  s/\.jpg$//i; #togliamo l'estensione
  my ($autore,$opera) = split/\s*-\s*/;
  system "$prog $autore $opera";
}
#-----cut-here------------------

-- 
Leo TheHobbit 
IRCnet #leiene
ICQ 56656060

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GED/CS d? s-:+>-: a C+++ U+++ L++(+++)>++++ P+++>+++++ E+(++) 
W++ N+ K? o? !w O? M V--- PS+++ PE-- Y+ GPG+ t++ 5? X- R+ tv+ 
b++++ D? DI? G e++++ h(+) r--(---) y--(+)>+++*
------END GEEK CODE BLOCK------



Reply to: