shell/Perl question
am 02.11.2004 05:21:44 von vick Julius
Hi everybody
I have several directories (around 10) named ABC, DEF, GHI,...
Each directory contains more than 50 files named, for example, 1.jpg, 2.jpg,
3.jpg,...50.jpg
These names are the same in each directory (this is what digital cameras do,
they give the same names...)
My problem is: I want to put all these files in the same directory, for
example, Photos, with the following names:
1ABC.jpg, 2ABC.jpg, ...50ABC.jpg, 1DEF.jpg, 2DEF.jpg...50DEF.jpg,...
each image filename (such as 1.jpg) will be split and to insert the name of
the directory (such as ABC..) after the first part of the name and finally
append the extension (.jpg) to the filename.
Any idea?
Thanks
Vick
____________________________________________________________ _____
Don't just search. Find. Check out the new MSN Search!
http://search.msn.com/
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: shell/Perl question
am 02.11.2004 07:58:21 von Glynn Clements
vick Julius wrote:
> I have several directories (around 10) named ABC, DEF, GHI,...
> Each directory contains more than 50 files named, for example, 1.jpg, 2.jpg,
> 3.jpg,...50.jpg
> These names are the same in each directory (this is what digital cameras do,
> they give the same names...)
> My problem is: I want to put all these files in the same directory, for
> example, Photos, with the following names:
> 1ABC.jpg, 2ABC.jpg, ...50ABC.jpg, 1DEF.jpg, 2DEF.jpg...50DEF.jpg,...
> each image filename (such as 1.jpg) will be split and to insert the name of
> the directory (such as ABC..) after the first part of the name and finally
> append the extension (.jpg) to the filename.
Two examples:
for dir in ABC DEF GHI ; do
for file in `(cd "$dir" && echo *.jpg)` ; do
mv "$dir/$file" "Photos/${file%%.jpg}$dir.jpg"
done
done
find . -type f | sed 's!^\./\(.*\)/\(.*\)\.jpg$!mv \1/\2.jpg Photos/\2\1.jpg!' | sh
If any of the filenames contain spaces, it gets more complex.
--
Glynn Clements
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: shell/Perl question
am 02.11.2004 08:50:48 von Dan Kubilos
love Vick's short ones.
I use perl for tasks like this.
There is a perl module called File::Copy that is great for this.
something like.
opendir(HANDLE, "dir to read" ).
while ( $eachfile = readdir( HANDLE ) ) {
move( "$eachfile", "new_location/new_prefix_$eachfile
}
I can send you examples if you are interested.
You might also look at
http://www.stanford.edu/~epop/igal/
To organize your photos.
On Tue, 2 Nov 2004, Glynn Clements wrote:
>
> vick Julius wrote:
>
> > I have several directories (around 10) named ABC, DEF, GHI,...
> > Each directory contains more than 50 files named, for example, 1.jpg, 2.jpg,
> > 3.jpg,...50.jpg
> > These names are the same in each directory (this is what digital cameras do,
> > they give the same names...)
> > My problem is: I want to put all these files in the same directory, for
> > example, Photos, with the following names:
> > 1ABC.jpg, 2ABC.jpg, ...50ABC.jpg, 1DEF.jpg, 2DEF.jpg...50DEF.jpg,...
> > each image filename (such as 1.jpg) will be split and to insert the name of
> > the directory (such as ABC..) after the first part of the name and finally
> > append the extension (.jpg) to the filename.
>
> Two examples:
>
> for dir in ABC DEF GHI ; do
> for file in `(cd "$dir" && echo *.jpg)` ; do
> mv "$dir/$file" "Photos/${file%%.jpg}$dir.jpg"
> done
> done
>
> find . -type f | sed 's!^\./\(.*\)/\(.*\)\.jpg$!mv \1/\2.jpg Photos/\2\1.jpg!' | sh
>
> If any of the filenames contain spaces, it gets more complex.
>
>
--
Dan Kubilos __\o_ ^
K-8 Tech Coord
http://www.oxnardsd.org
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: shell/Perl question
am 02.11.2004 11:20:46 von urgrue
i think i win for "shortest version", using mmv:
mmv "*/*.jpg" "Photos/#1#2.jpg"
On 2004.11.02 06:21, vick Julius wrote:
> Hi everybody
>
> I have several directories (around 10) named ABC, DEF, GHI,...
> Each directory contains more than 50 files named, for example, 1.jpg,
> 2.jpg, 3.jpg,...50.jpg
> These names are the same in each directory (this is what digital
> cameras do, they give the same names...)
> My problem is: I want to put all these files in the same directory,
> for example, Photos, with the following names:
> 1ABC.jpg, 2ABC.jpg, ...50ABC.jpg, 1DEF.jpg, 2DEF.jpg...50DEF.jpg,...
> each image filename (such as 1.jpg) will be split and to insert the
> name of the directory (such as ABC..) after the first part of the
> name and finally append the extension (.jpg) to the filename.
>
> Any idea?
> Thanks
>
> Vick
>
> ____________________________________________________________ _____
> Don't just search. Find. Check out the new MSN Search!
> http://search.msn.com/
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-
> admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: shell/Perl question
am 03.11.2004 05:04:10 von vick Julius
Thanks Glynn
I tried the first method and It works fine.
What is the use of echo *.jpg in (cd "$dir" && echo *.jpg)? Is it mandatory?
Where can I find more details on ${file%%.jpg} stuff? is it in the bash
manual?...
thanks
Vick
>From: Glynn Clements
>To: "vick Julius"
>CC: linux-admin@vger.kernel.org
>Subject: Re: shell/Perl question
>Date: Tue, 2 Nov 2004 06:58:21 +0000
>
>
>vick Julius wrote:
>
> > I have several directories (around 10) named ABC, DEF, GHI,...
> > Each directory contains more than 50 files named, for example, 1.jpg,
>2.jpg,
> > 3.jpg,...50.jpg
> > These names are the same in each directory (this is what digital cameras
>do,
> > they give the same names...)
> > My problem is: I want to put all these files in the same directory, for
> > example, Photos, with the following names:
> > 1ABC.jpg, 2ABC.jpg, ...50ABC.jpg, 1DEF.jpg, 2DEF.jpg...50DEF.jpg,...
> > each image filename (such as 1.jpg) will be split and to insert the name
>of
> > the directory (such as ABC..) after the first part of the name and
>finally
> > append the extension (.jpg) to the filename.
>
>Two examples:
>
> for dir in ABC DEF GHI ; do
> for file in `(cd "$dir" && echo *.jpg)` ; do
> mv "$dir/$file" "Photos/${file%%.jpg}$dir.jpg"
> done
> done
>
> find . -type f | sed 's!^\./\(.*\)/\(.*\)\.jpg$!mv \1/\2.jpg
>Photos/\2\1.jpg!' | sh
>
>If any of the filenames contain spaces, it gets more complex.
>
>--
>Glynn Clements
____________________________________________________________ _____
Don't just search. Find. Check out the new MSN Search!
http://search.msn.com/
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: shell/Perl question
am 03.11.2004 05:44:25 von Glynn Clements
vick Julius wrote:
> > for dir in ABC DEF GHI ; do
> > for file in `(cd "$dir" && echo *.jpg)` ; do
> > mv "$dir/$file" "Photos/${file%%.jpg}$dir.jpg"
> > done
> > done
> >
> What is the use of echo *.jpg in (cd "$dir" && echo *.jpg)?
That fragment outputs the list of files in the current directory
(which will be $dir due to the preceding "cd").
> Is it mandatory?
There are other ways to do it; e.g. using "ls *.jpg" would also have
worked, but "echo" is built in to the shell.
> Where can I find more details on ${file%%.jpg} stuff? is it in the bash
> manual?...
It's in the bash manual, in the section entitled "Parameter Expansion".
--
Glynn Clements
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html