Re: adding leading zeros to a filename

From: Kevin Rodgers (ihs_4664_at_yahoo.com)
Date: 01/28/05


Date: Fri, 28 Jan 2005 14:36:47 -0700

rupert wrote:
> Basically I know nothing about shell scripting. I'm guessing I can
> write such a beast that will list the contents of a directory

for file in *.jpg; do
  ...
done

or

ls *.jpg | while read file; do
...
done

> and rename
> the files as it goes.

mv $file $new_file

> I'm an apple OSX user, so not a unix guru and have had a look through
> stuff on perl and regular expressions and although I sort of understand
> some of it I've not managed to work out how to make it do what I want.
> I can write c, c++, and c# stuff on pc's (the day job) so am not a
> novice when it comes to software, but don't have a unix background at
> all - adn shell scripts/perl/grep etc are unknown territory. So
> basically was hoping for an expert to tell me how to do it! ...and this
> looked like a promising place to ask...

`man sh` is a good place to start. But I prefer ksh:

typeset -Z3 number
for file in *.jpg; do
  number=${file%.jpg}
  mv $file $number.jpg
done

-- 
Kevin Rodgers


Relevant Pages

  • Re: adding leading zeros to a filename
    ... > rupert wrote: ... >> Basically I know nothing about shell scripting. ... I'm guessing I can ... >> write such a beast that will list the contents of a directory ...
    (comp.unix.shell)
  • Re: Beta
    ... steve wrote: ... > I meant .jpg, sorry. ... Still guessing that is your issue. ... > Might be a ton of work if you have a lot of pics, ...
    (microsoft.public.windowsxp.moviemaker)
  • Re: This Chick Is Hot
    ... NiGHTS [mWo] ... "Beware the beast in black... ...
    (rec.sport.pro-wrestling)