LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 05-07-2007, 12:03 PM   #1
jimmybond01
LQ Newbie
 
Registered: May 2007
Posts: 1

Rep: Reputation: 0
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
 
Old 05-07-2007, 12:08 PM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Code:
for fname in DSC00*.jpg; do
   mv "$fname" "${fname#DSC00}"
done
 
Old 05-07-2007, 12:10 PM   #3
hashash
Member
 
Registered: Apr 2007
Posts: 31

Rep: Reputation: 15
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.
 
Old 05-07-2007, 12:11 PM   #4
hashash
Member
 
Registered: Apr 2007
Posts: 31

Rep: Reputation: 15
jschiwal: neat
 
Old 05-07-2007, 07:15 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Code:
rename dsc00 ''  *jpg


Cheers,
Tink
 
Old 05-07-2007, 07:56 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,222

Rep: Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019
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.
 
Old 05-08-2007, 12:43 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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
 
Old 05-08-2007, 06:09 AM   #8
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,067

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
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
 
Old 05-08-2007, 06:14 AM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,222

Rep: Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019
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.
 
Old 05-08-2007, 06:17 AM   #10
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 35
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'"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i convert psf picture to jpg? laszlar Linux - Software 7 05-19-2008 02:58 PM
Convert move frames (avi/dvi/etc) to images(png/jpg/etc) 3saul Linux - Software 1 03-05-2006 09:29 PM
convert wmv to pnm/jpg in linux LexMillian Linux - Software 3 09-12-2005 06:23 AM
renaming all JPG to jpg quickk Linux - Newbie 8 09-05-2004 01:23 AM
How to convert macintosh pic to gif/jpg lervere Linux - General 1 07-22-2001 08:02 PM


All times are GMT -5. The time now is 12:02 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration