The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
rename a lot of files again ajp7701 Shell Programming and Scripting 11 03-31-2008 08:36 PM
Script to rename files Dinkster UNIX for Dummies Questions & Answers 5 01-22-2008 08:55 AM
script to rename files with current date and copy it. logic0 UNIX for Dummies Questions & Answers 6 05-01-2007 06:13 AM
Rename Files with a script ? yoveln OS X (Apple) 1 02-08-2004 12:45 PM
How to rename files? CompuTelSystem UNIX for Dummies Questions & Answers 9 05-14-2002 04:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-01-2008
cpreovol cpreovol is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
Script to rename files

Let me preface this by stating I have absolutely no idea what I'm doing in this arena, but I'm in need of a little help here.

I need to take filenames like this: amwed_0402c-slug~1-cp.jpg
And reduce them to slug~1.jpg

That is, I need to remove the first 12 and last 3 characters. The characters will frequently be different, but they will always be the first 12 and last three (before the file extension).

Anyway, I need to be able to execute this using Automator on the Mac so I can incorporate it into some photoshop actions.

Can anyone tell me how to do this? Any help would be much appreciated.
  #2 (permalink)  
Old 04-01-2008
cpreovol cpreovol is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
Anyway, the Automator reference is a red herring, I see how to execute it using this program, but I don't know how to write the script.

Thanks,
CP
  #3 (permalink)  
Old 04-01-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
something like:


Code:
# echo "amwed_0402c-slug~1-cp.jpg" | awk '{FS=".";print substr($1,13,length($1)-15)"."$2}'
slug~1.jpg

should work...
  #4 (permalink)  
Old 04-01-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,374
Quote:
Originally Posted by cpreovol View Post
I need to take filenames like this: amwed_0402c-slug~1-cp.jpg
And reduce them to slug~1.jpg

That is, I need to remove the first 12 and last 3 characters. The characters will frequently be different, but they will always be the first 12 and last three (before the file extension).


Code:
file=amwed_0402c-slug~1-cp.jpg
## Save the extension
ext=${file##*.}

## Extract the name without the extension
name=${file%.*}

## Remove the first 12 characters from the name
name=${name#????????????}

## Remove the last three characters
name=${name%???}

## Put the new filename together
newfile=$name.$ext

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate 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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0