Re: need help with bash command
Le Jeu 20 novembre 2008 16:18, tôba a écrit :
> icon_3620_0_1.jpg
> icon_3616_0_1.jpg
> icon_3563_0_1.jpg
>
> The goal is to create a directory called 3620 and move the
> icon_3620_0_1.jpg file into this directory.
>
> So, I did like this for test:
> # for a in `ls | sed -e s'/_/ /g' | awk '{print $2}'`; do echo
> icon_$a_0_1.jpg; done
for a in `ls`; do DIR=`echo $a | cut -d_ -f2`; echo mkdir -p $DIR
/$a; echo rmdir $DIR/$a; echo mv $a $DIR/$a; done
First, compute the dirname to put the file in.
Second, create a directory corresponding to the full destination path
including the filename to create the parent directory if it does not
exists
Third, remove the directory with the name of the file
Fourth, move the file
The command line includes "echo" for you to see what will be done. When
you want the job to be done, just remove the "echo" before mkdir, rmdir
and mv.
Fanfan
--
http://www.cerbelle.net - http://www.afdm-idf.org
Reply to: