renaming issues

Need help with C, C++, perl, python, etc?

renaming issues

Postby Blyiss » 2007-04-26 17:30

I have a folder that contains a lot of files of the following type: 0001, 0002, 0003, 0004, ..., etc.

Question: how can I rename all these file so that zeros would be removed and I had files like 1, 2, 3, 4, ..., etc?
Blyiss
 
Posts: 585
Joined: 2007-02-10 19:47
Location: Yakutia

Postby chrismortimore » 2007-04-26 17:42

Code: Select all
for i in `ls -1 --color=never`; do mv ${i} `echo ${i} | sed -e 's/^0*//g'`; done
That'll do it.

EDIT: a slight tweak to make it a little better
Desktop: AMD Athlon64 3800+ Venice Core, 2GB PC3200, 5x320GB WD 7200rpm Caviar RE2 (RAID5), Nvidia 6600GT 256MB
Laptop: Intel Pentium M 1.5GHz, 512MB PC2700, 60GB 5400rpm IBM TravelStar, Nvidia 5200Go 64MB
User avatar
chrismortimore
 
Posts: 862
Joined: 2007-04-24 06:34
Location: Edinburgh, UK

Postby Blyiss » 2007-04-26 17:54

Thanks, it works! Great!
Blyiss
 
Posts: 585
Joined: 2007-02-10 19:47
Location: Yakutia

Postby chrismortimore » 2007-04-26 18:01

Blyiss wrote:Thanks, it works! Great!
My pleasure :)
Desktop: AMD Athlon64 3800+ Venice Core, 2GB PC3200, 5x320GB WD 7200rpm Caviar RE2 (RAID5), Nvidia 6600GT 256MB
Laptop: Intel Pentium M 1.5GHz, 512MB PC2700, 60GB 5400rpm IBM TravelStar, Nvidia 5200Go 64MB
User avatar
chrismortimore
 
Posts: 862
Joined: 2007-04-24 06:34
Location: Edinburgh, UK


Return to Programming

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable