Re: Batch file rename question (consecutive file numbers)
- From: gibbonsp <gibbonsp@xxxxxxxxx>
- Date: Fri, 31 Aug 2007 20:55:11 -0000
This is EXACTLY what I was looking for - thank you very much for your
help. I just piped to bash, and all of my files were renamed
accordingly. I did have to be in sh (instead of bash), and
export n=''
before executing the command, after multiple uses. VERY COOL!!!!
Peter
On Aug 31, 1:53 pm, Piotr KUCHARSKI <cho...@xxxxxxxxxx> wrote:
gibbonsp <gibbo...@xxxxxxxxx> wrote:
I'm good with Unix, but I haven't learned Perl yet.... I know Perl can
do this, but since I don't know Perl yet, I'm a little hung up.
Problem:
I need to rename a batch of files:
foo_001.jpg
foo_002.jpg
foo_003.jpg
bar_001.jpg
bar_002.jpg
bar_003.jpg
....and so on.
I need to take the number on these files (notice how the number is
duplicated on foo and bar) and make the entire batch consecutive. In
other words, I want the file list to look like this:
foo_001.jpg
foo_002.jpg
foo_003.jpg
bar_004.jpg
bar_005.jpg
bar_006.jpg
....and so on.
I'd appreciate any ideas! I just feel like this is so simple and I'm
just not seeing the answer!
$ ls
foo_001.jpg
foo_002.jpg
foo_003.jpg
bar_001.jpg
bar_002.jpg
bar_003.jpg
$ n=0; for i in *; do n=$((n+1)); nn=`printf "%03d" $n`;
echo mv $i ${i/_*\./_$nn.}; done
mv foo_001.jpg foo_001.jpg
mv foo_002.jpg foo_002.jpg
mv foo_003.jpg foo_003.jpg
mv bar_001.jpg bar_004.jpg
mv bar_002.jpg bar_005.jpg
mv bar_003.jpg bar_006.jpg
Seems like what you want.
p.
PS Always test first with "echo mv" before actual "mv". Could be good
idea to use "mv -i", just in case.
--
Beware of he who would deny you access to information, for in his
heart he dreams himself your master. -- Commissioner Pravin Lal
.
- References:
- Batch file rename question (consecutive file numbers)
- From: gibbonsp
- Re: Batch file rename question (consecutive file numbers)
- From: Piotr KUCHARSKI
- Batch file rename question (consecutive file numbers)
- Prev by Date: Re: Batch file rename question (consecutive file numbers)
- Previous by thread: Re: Batch file rename question (consecutive file numbers)
- Index(es):
Relevant Pages
|
|