nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

renaming and number padding using directory as guide, help

This is a discussion on renaming and number padding using directory as guide, help within the Shell scripting forums, part of the Development/Scripting category; I need to take a series of image files, all numbered consecuativly, that were recently dumped in a directory and ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 02-13-2007, 07:19 AM
Junior Member
User
 
Join Date: Feb 2007
Posts: 6
Rep Power: 0
TiredOrangeCat
Default renaming and number padding using directory as guide, help

I need to take a series of image files, all numbered consecuativly, that were recently dumped in a directory and rename them to pieces of the directories path. Assume all directories are structured as this one so that I may use this script to easly sort and rename files.

pt.1
path : /home/shots/pic/seasons/winter/snowy

I need the script to recognize pieces of the path as variables to the images new name.

pt.2
path : /home/$NAME/pic/seasons/$SEASON/

I then need the file which is named xyxy.1.tif to be named in the following convention

pt.3
name : $NAME_$SEASON.0001.tif

the number needs to be repadded with 4 digits

I have been hacking at it for the past two days and have comeup with a rather large mess and have finally broken down and called out for help. I had it half working in Perl my knowlege of that is even more limited then the BASH shell. Thanks
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-15-2007, 09:40 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Following command will print
Code:
echo /home/shots/pic/seasons/winter/snowy  | cut -d'/' -f3
shots

You can store to a variable:
Code:
NAME=$(echo /home/shots/pic/seasons/winter/snowy  | cut -d'/' -f3)
SEASON=$(echo /home/shots/pic/seasons/winter/snowy  | cut -d'/' -f7)
Adjust field (-f) as per your need.

try above and let me know if you need any further help
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

Similar Threads

Thread Thread Starter Forum Replies Last Post
Guide to configure Linux Mail Server javed Mail Servers 0 12-24-2007 12:59 PM
UNIX Display or list number of files in a current directory raj Getting started tutorials 1 12-07-2007 11:55 AM
Structured cabling Guide ssent12 Computer Networking and Internet/broadband 4 06-11-2007 04:59 PM
Number of Visits in AWStats! honey bee Linux software 3 04-01-2006 10:51 PM
Plz Guide Me... kartheekpn Shell scripting 3 05-18-2005 08:01 PM


All times are GMT +5.5. The time now is 07:20 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36