Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-07-2007, 12:03 PM
|
#1
|
|
LQ Newbie
Registered: May 2007
Posts: 1
Rep:
|
HELP! BASH - Convert filenames from dsc00***.jpg to *.jpg
Hi!
For a web project I'm doing I need to convert all my digital camera files from their dsc00***.jpg to ***.jpg. Basically, I need to remove the dsc00 part in the filenames of around 500 files. How do I go about doing this in BASH. Can anyone please help me with this?
Thanks a lot!
-WHOMAI
|
|
|
|
05-07-2007, 12:08 PM
|
#2
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Code:
for fname in DSC00*.jpg; do
mv "$fname" "${fname#DSC00}"
done
|
|
|
|
05-07-2007, 12:10 PM
|
#3
|
|
Member
Registered: Apr 2007
Posts: 31
Rep:
|
Am a tsch person.. (thats another shell like BASH).
You should be able to convert this into bash...
>foreach i ( dsc00*jpg )
foreach? set j = `echo $i|sed -e 's/dsc00//'`
foreach? mv $i $j
foreach? end
they key line is to use sed (stream-editor) to get the file name without dsc00
the syntax s/dsc00// is explained as:
subsitute dsc00 with nothing..
hope that helps.
|
|
|
|
05-07-2007, 12:11 PM
|
#4
|
|
Member
Registered: Apr 2007
Posts: 31
Rep:
|
jschiwal: neat 
|
|
|
|
05-07-2007, 07:15 PM
|
#5
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
Code:
rename dsc00 '' *jpg
Cheers,
Tink
|
|
|
|
05-07-2007, 07:56 PM
|
#6
|
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,288
|
Quote:
|
Originally Posted by hashash
jschiwal: neat 
|
+1
@Tink, my "rename" wants a perl regex as parameter 1 - it didn't like your solution at all.
|
|
|
|
05-08-2007, 12:43 AM
|
#7
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
Hmmm ... works in slackware :}
In Slack it's not a perl-script but a binary, part
of the util-linux package ...
[edit]
Funny. Debilian and Ubunut both don't seem to have
the file as part of util-linux, even though the original
changelog entry mentions it, and the Debilian.gz doesn't
mention its removal ...
[/edit]
Cheers,
Tink
Last edited by Tinkster; 05-08-2007 at 12:54 AM.
Reason: Added findings about debilian and its spawn
|
|
|
|
05-08-2007, 06:09 AM
|
#8
|
|
Senior Member
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 3,832
|
AFAIK it is perl in Debian and the correct command is:
rename s/dsc00// dsc00*.jpg
Maybe this is what syg00 meant by 'regular expression'.
jlinkels
|
|
|
|
05-08-2007, 06:14 AM
|
#9
|
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,288
|
T'was indeed; I've been trying to find Tink's util-linux version on a Ubuntu laptop.
Not being a regular Debian (or Slack for that matter) user.
|
|
|
|
05-08-2007, 06:17 AM
|
#10
|
|
Member
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212
Rep:
|
Quote:
|
Originally Posted by jimmybond01
[...]
Basically, I need to remove the dsc00 part in the filenames of around 500 files. How do I go about doing this in BASH.
[...]
|
In bash?
Code:
zsh -c "autoload zmv && zmv 'dsc00(*).jpg' '\$1.jpg'"
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:27 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|