LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
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: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
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: 38
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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:09 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration