* [gentoo-user] [OT] Filename modification with suffix
@ 2005-12-29 13:24 Marco Calviani
2005-12-29 13:36 ` David Morgan
` (3 more replies)
0 siblings, 4 replies; 15+ messages in thread
From: Marco Calviani @ 2005-12-29 13:24 UTC (permalink / raw
To: gentoo-user
Hi list,
maybe this question is a little bit related since it regards non
Gentoo-specific topics.
I would like to add a specific suffix to a list of files. For example
i have files of the type:
duck1.jpg
duck2.jpg
duck3.jpg
and i would like them to become:
donald_duck1.jpg
donald_duck2.jpg
donald_duck3.jpg
Does somebody knows a simple way to do this via shell?
Thanks in advance,
MC
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-29 13:24 [gentoo-user] [OT] Filename modification with suffix Marco Calviani
@ 2005-12-29 13:36 ` David Morgan
2005-12-29 17:43 ` Marco Calviani
2005-12-29 13:38 ` Christoph Eckert
` (2 subsequent siblings)
3 siblings, 1 reply; 15+ messages in thread
From: David Morgan @ 2005-12-29 13:36 UTC (permalink / raw
To: gentoo-user
On 14:24 Thu 29 Dec , Marco Calviani wrote:
> i have files of the type:
>
> duck1.jpg
> duck2.jpg
> duck3.jpg
>
> and i would like them to become:
>
> donald_duck1.jpg
> donald_duck2.jpg
> donald_duck3.jpg
>
for i in duck*.jpg ; do mv ${i} donald_${i} ; done
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-29 13:24 [gentoo-user] [OT] Filename modification with suffix Marco Calviani
2005-12-29 13:36 ` David Morgan
@ 2005-12-29 13:38 ` Christoph Eckert
2005-12-29 13:53 ` David Morgan
2005-12-29 13:41 ` Ciaran McCreesh
2005-12-30 0:57 ` Jerry McBride
3 siblings, 1 reply; 15+ messages in thread
From: Christoph Eckert @ 2005-12-29 13:38 UTC (permalink / raw
To: gentoo-user
> i have files of the type:
>
> duck1.jpg
> duck2.jpg
> duck3.jpg
>
> and i would like them to become:
>
> donald_duck1.jpg
> donald_duck2.jpg
> donald_duck3.jpg
>
> Does somebody knows a simple way to do this via shell?
for i in $(ls *.jpg); do mv $i donald_$i; done
Best regards
ce
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-29 13:24 [gentoo-user] [OT] Filename modification with suffix Marco Calviani
2005-12-29 13:36 ` David Morgan
2005-12-29 13:38 ` Christoph Eckert
@ 2005-12-29 13:41 ` Ciaran McCreesh
2005-12-30 0:57 ` Jerry McBride
3 siblings, 0 replies; 15+ messages in thread
From: Ciaran McCreesh @ 2005-12-29 13:41 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 484 bytes --]
On Thu, 29 Dec 2005 14:24:31 +0100 Marco Calviani
<marco.calviani@gmail.com> wrote:
| duck1.jpg
| duck2.jpg
| duck3.jpg
|
| and i would like them to become:
|
| donald_duck1.jpg
| donald_duck2.jpg
| donald_duck3.jpg
|
| Does somebody knows a simple way to do this via shell?
rename '' 'donald_' duck*.jpg
--
Ciaran McCreesh : Gentoo Developer (King of all Londinium)
Mail : ciaranm at gentoo.org
Web : http://dev.gentoo.org/~ciaranm
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-29 13:38 ` Christoph Eckert
@ 2005-12-29 13:53 ` David Morgan
2005-12-29 17:24 ` Christoph Eckert
2005-12-31 19:38 ` Matthias Bethke
0 siblings, 2 replies; 15+ messages in thread
From: David Morgan @ 2005-12-29 13:53 UTC (permalink / raw
To: gentoo-user
On 14:38 Thu 29 Dec , Christoph Eckert wrote:
> $(ls *.jpg)
ick!
(incidentally, http://www.ruhr.de/home/smallo/award.html#ls)
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-29 13:53 ` David Morgan
@ 2005-12-29 17:24 ` Christoph Eckert
2005-12-31 19:38 ` Matthias Bethke
1 sibling, 0 replies; 15+ messages in thread
From: Christoph Eckert @ 2005-12-29 17:24 UTC (permalink / raw
To: gentoo-user
> > $(ls *.jpg)
>
> ick!
>
> (incidentally, http://www.ruhr.de/home/smallo/award.html#ls)
I forgot to clarify that the CPU of my notebook usually is bored and
waits until I move my mouse, so some ls processes can make it a bit
busy :) .
Best regards
ce
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-29 13:36 ` David Morgan
@ 2005-12-29 17:43 ` Marco Calviani
0 siblings, 0 replies; 15+ messages in thread
From: Marco Calviani @ 2005-12-29 17:43 UTC (permalink / raw
To: gentoo-user
2005/12/29, David Morgan <david.morgan@wadham.oxford.ac.uk>:
>
> for i in duck*.jpg ; do mv ${i} donald_${i} ; done
Well! Thank you very much David. That solved my problem!
Best regards,
MC
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-29 13:24 [gentoo-user] [OT] Filename modification with suffix Marco Calviani
` (2 preceding siblings ...)
2005-12-29 13:41 ` Ciaran McCreesh
@ 2005-12-30 0:57 ` Jerry McBride
2005-12-30 2:59 ` Lithion
3 siblings, 1 reply; 15+ messages in thread
From: Jerry McBride @ 2005-12-30 0:57 UTC (permalink / raw
To: gentoo-user
On Thursday 29 December 2005 08:24, Marco Calviani wrote:
> Hi list,
> maybe this question is a little bit related since it regards non
> Gentoo-specific topics.
> I would like to add a specific suffix to a list of files. For example
> i have files of the type:
>
> duck1.jpg
> duck2.jpg
> duck3.jpg
>
> and i would like them to become:
>
> donald_duck1.jpg
> donald_duck2.jpg
> donald_duck3.jpg
>
> Does somebody knows a simple way to do this via shell?
>
Did anyone mention RENAME???
A simple "rename duck donald_duck duck*.jpg" would work well also....
Cheers.
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-30 0:57 ` Jerry McBride
@ 2005-12-30 2:59 ` Lithion
0 siblings, 0 replies; 15+ messages in thread
From: Lithion @ 2005-12-30 2:59 UTC (permalink / raw
To: gentoo-user
Such a question shows the power of bash programming.
Method1 :
ls -1 *.jpg | while read file; do mv "$file" \
"donald_$file"; done
Method2 :
ls -1 *.jpg | awk '{ print "mv "$1" donald_"$1; } | \
/bin/bash
Method3 :
find -name "*.jpg" -exec mv {} donald_{} ';'
On Fri, 30 Dec 2005 11:57 am, Jerry McBride wrote:
> On Thursday 29 December 2005 08:24, Marco Calviani wrote:
> > Hi list,
> > maybe this question is a little bit related since it regards non
> > Gentoo-specific topics.
> > I would like to add a specific suffix to a list of files. For
> > example i have files of the type:
> >
> > duck1.jpg
> > duck2.jpg
> > duck3.jpg
> >
> > and i would like them to become:
> >
> > donald_duck1.jpg
> > donald_duck2.jpg
> > donald_duck3.jpg
> >
> > Does somebody knows a simple way to do this via shell?
>
> Did anyone mention RENAME???
>
> A simple "rename duck donald_duck duck*.jpg" would work well also....
>
> Cheers.
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-29 13:53 ` David Morgan
2005-12-29 17:24 ` Christoph Eckert
@ 2005-12-31 19:38 ` Matthias Bethke
2005-12-31 21:04 ` [gentoo-user] " Francesco Talamona
2005-12-31 22:19 ` [gentoo-user] " Neil Bothwick
1 sibling, 2 replies; 15+ messages in thread
From: Matthias Bethke @ 2005-12-31 19:38 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 1154 bytes --]
Hi David,
on Thursday, 2005-12-29 at 13:53:17, you wrote:
> > $(ls *.jpg)
>
> ick!
>
> (incidentally, http://www.ruhr.de/home/smallo/award.html#ls)
Well, it's bad in two ways, and even the example on the above webpage is
wrong. For one thing, "ls" is useless here. For another, it will break
on spaces in filenames, unlike shell globbing:
| $ touch "foo bar.jpg"
| $ for f in *.jpg; do echo $f; done
| foo bar.jpg
| $ for f in `ls *.jpg`; do echo $f; done
| foo
| bar.jpg
| $ for f in `ls *.jpg`; do echo "$f"; done
| foo
| bar.jpg
The bottommost try shows that the comment "newbies will often forget the
quotes, too" is wrong -- it won't work either way. If you have to use
a program that outputs a filename per line like ls, use a read loop:
| $ ls *.jpg | while read f; do echo "$f"; done
| foo bar.jpg
The quotes are useless for "echo" here, but for other commands you'll
usually need them to keep the command form taking filenames with sapaces
as separate arguments.
cheers!
Matthias
--
I prefer encrypted and signed messages. KeyID: FAC37665
Fingerprint: 8C16 3F0A A6FC DF0D 19B0 8DEF 48D9 1700 FAC3 7665
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* [gentoo-user] Re: [OT] Filename modification with suffix
2005-12-31 19:38 ` Matthias Bethke
@ 2005-12-31 21:04 ` Francesco Talamona
2005-12-31 21:11 ` Francesco Talamona
2005-12-31 22:19 ` [gentoo-user] " Neil Bothwick
1 sibling, 1 reply; 15+ messages in thread
From: Francesco Talamona @ 2005-12-31 21:04 UTC (permalink / raw
To: gentoo-user
On Saturday 31 December 2005 20:38, Matthias Bethke wrote:
> Hi David,
>
> on Thursday, 2005-12-29 at 13:53:17, you wrote:
> > > $(ls *.jpg)
> >
> > ick!
> >
> > (incidentally, http://www.ruhr.de/home/smallo/award.html#ls)
>
> Well, it's bad in two ways, and even the example on the above webpage
> is wrong. For one thing, "ls" is useless here. For another, it will
> break
>
> on spaces in filenames, unlike shell globbing:
> | $ touch "foo bar.jpg"
> | $ for f in *.jpg; do echo $f; done
> | foo bar.jpg
> | $ for f in `ls *.jpg`; do echo $f; done
> | foo
> | bar.jpg
> | $ for f in `ls *.jpg`; do echo "$f"; done
> | foo
> | bar.jpg
>
> The bottommost try shows that the comment "newbies will often forget
> the quotes, too" is wrong -- it won't work either way. If you have to
> use
>
> a program that outputs a filename per line like ls, use a read loop:
> | $ ls *.jpg | while read f; do echo "$f"; done
> | foo bar.jpg
>
> The quotes are useless for "echo" here, but for other commands you'll
> usually need them to keep the command form taking filenames with
> sapaces as separate arguments.
>
> cheers!
> Matthias
It is the first part of the command, the one expanding ls output that
needs quotes...
$ for f in $"`ls *.jpg`"; do echo $f; done
foo bar.jpg
Ciao
Francesco
--
Linux Version 2.6.14-gentoo-r6, Compiled #0 PREEMPT Sat Dec 31 01:17:32
CET 2005
One 1GHz AMD Athlon 64 Processor, 2GB RAM, 2007.23 Bogomips Total
aemaeth
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* [gentoo-user] Re: [OT] Filename modification with suffix
2005-12-31 21:04 ` [gentoo-user] " Francesco Talamona
@ 2005-12-31 21:11 ` Francesco Talamona
2005-12-31 21:47 ` Alexander Skwar
0 siblings, 1 reply; 15+ messages in thread
From: Francesco Talamona @ 2005-12-31 21:11 UTC (permalink / raw
To: gentoo-user
On Saturday 31 December 2005 22:04, Francesco Talamona wrote:
> $ for f in $"`ls *.jpg`"; do echo $f; done
> foo bar.jpg
Little typo, I made an hybrid :-)
[sko@aemaeth:~]$ for f in "$(ls *.jpg)"; do echo $f; done
foo bar.jpg
[sko@aemaeth:~]$ for f in "`ls *.jpg`"; do echo $f; done
foo bar.jpg
Ciao
Francesco
--
Linux Version 2.6.14-gentoo-r6, Compiled #0 PREEMPT Sat Dec 31 01:17:32
CET 2005
One 2.2GHz AMD Athlon 64 Processor, 2GB RAM, 4415.90 Bogomips Total
aemaeth
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] Re: [OT] Filename modification with suffix
2005-12-31 21:11 ` Francesco Talamona
@ 2005-12-31 21:47 ` Alexander Skwar
2005-12-31 22:26 ` Francesco Talamona
0 siblings, 1 reply; 15+ messages in thread
From: Alexander Skwar @ 2005-12-31 21:47 UTC (permalink / raw
To: gentoo-user
Francesco Talamona schrieb:
> On Saturday 31 December 2005 22:04, Francesco Talamona wrote:
>> $ for f in $"`ls *.jpg`"; do echo $f; done
>> foo bar.jpg
>
> Little typo, I made an hybrid :-)
>
> [sko@aemaeth:~]$ for f in "$(ls *.jpg)"; do echo $f; done
> foo bar.jpg
> [sko@aemaeth:~]$ for f in "`ls *.jpg`"; do echo $f; done
> foo bar.jpg
Still wrong. Still just one line of output. Cause of
error: The use of " in the "for" loop.
Further: No need to use ls.
Alexander Skwar
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-user] [OT] Filename modification with suffix
2005-12-31 19:38 ` Matthias Bethke
2005-12-31 21:04 ` [gentoo-user] " Francesco Talamona
@ 2005-12-31 22:19 ` Neil Bothwick
1 sibling, 0 replies; 15+ messages in thread
From: Neil Bothwick @ 2005-12-31 22:19 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 645 bytes --]
On Sat, 31 Dec 2005 20:38:32 +0100, Matthias Bethke wrote:
> | $ ls *.jpg | while read f; do echo "$f"; done
> | foo bar.jpg
> The quotes are useless for "echo" here, but for other commands you'll
> usually need them to keep the command form taking filenames with sapaces
> as separate arguments.
The quotes are only unnecessary for echo if filenames only contain single
spaces, multiple consecutive spaces will be converted to a single space
if not quoted.
$ echo "Hello there"
Hello there
$ echo Hello there
Hello there
--
Neil Bothwick
Never get into fights with ugly people because they have nothing to lose.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* [gentoo-user] Re: [OT] Filename modification with suffix
2005-12-31 21:47 ` Alexander Skwar
@ 2005-12-31 22:26 ` Francesco Talamona
0 siblings, 0 replies; 15+ messages in thread
From: Francesco Talamona @ 2005-12-31 22:26 UTC (permalink / raw
To: gentoo-user
On Saturday 31 December 2005 22:47, Alexander Skwar wrote:
> Francesco Talamona schrieb:
> > On Saturday 31 December 2005 22:04, Francesco Talamona wrote:
> >> $ for f in $"`ls *.jpg`"; do echo $f; done
> >> foo bar.jpg
> >
> > Little typo, I made an hybrid :-)
> >
> > [sko@aemaeth:~]$ for f in "$(ls *.jpg)"; do echo $f; done
> > foo bar.jpg
> > [sko@aemaeth:~]$ for f in "`ls *.jpg`"; do echo $f; done
> > foo bar.jpg
>
> Still wrong. Still just one line of output. Cause of
> error: The use of " in the "for" loop.
>
> Further: No need to use ls.
You are right! I tested in a folder containing just "foo bar.jpg"
Of course a one-line output defeats the usefulness of "for" cycle :-)
cheers
Francesco
--
Linux Version 2.6.14-gentoo-r6, Compiled #0 PREEMPT Sat Dec 31 01:17:32
CET 2005
One 2.2GHz AMD Athlon 64 Processor, 2GB RAM, 4415.90 Bogomips Total
aemaeth
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2005-12-31 22:38 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-29 13:24 [gentoo-user] [OT] Filename modification with suffix Marco Calviani
2005-12-29 13:36 ` David Morgan
2005-12-29 17:43 ` Marco Calviani
2005-12-29 13:38 ` Christoph Eckert
2005-12-29 13:53 ` David Morgan
2005-12-29 17:24 ` Christoph Eckert
2005-12-31 19:38 ` Matthias Bethke
2005-12-31 21:04 ` [gentoo-user] " Francesco Talamona
2005-12-31 21:11 ` Francesco Talamona
2005-12-31 21:47 ` Alexander Skwar
2005-12-31 22:26 ` Francesco Talamona
2005-12-31 22:19 ` [gentoo-user] " Neil Bothwick
2005-12-29 13:41 ` Ciaran McCreesh
2005-12-30 0:57 ` Jerry McBride
2005-12-30 2:59 ` Lithion
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox