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 using shells script justbow Shell Programming and Scripting 3 08-03-2009 07:02 AM
Script to rename files cpreovol Shell Programming and Scripting 3 04-01-2008 12:45 PM
Script to rename files Dinkster UNIX for Dummies Questions & Answers 5 01-22-2008 08:55 AM
copy similar files only both at different locations using script. fed.linuxgossip Shell Programming and Scripting 1 11-23-2007 04:02 AM
Rename Files with a script ? yoveln OS X (Apple) 1 02-08-2004 12:45 PM

Reply
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 08-20-2009
rjanardhan83 rjanardhan83 is offline
Registered User
  
 

Join Date: May 2009
Posts: 8
Need script to rename the files in different locations

Hi everybody,

I need a script for below issue:

I have totally 15 different locations like */COUNTRY/in.
Only COUNTRy is the variable which changes for 15 countries.
For each location(one per country), there will be four files like abc_def_ddmmyyyy.txt, where ddmmyyyy is the old date.

I need a script which renames all the files for all the 15 countries to current date.
Can any body help on this please?

Regards,
Janardhan
  #2 (permalink)  
Old 08-20-2009
dr.house dr.house is offline
Registered User
  
 

Join Date: Dec 2008
Location: Switzerland
Posts: 229
Bash draft (untested):


Code:
DATE=$( date '+%d%m%Y' )
for COUNTRY in $COUNTRIES
do
  for FILE in $( ls $COUNTRY )
  do
    NAME=$( echo "$FILE" | sed "s/_[0-9]*.txt/_$DATE.txt/" )
    mv $COUNTRY/$FILE $COUNTRY/$NAME
  done
done

Reply

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 07:58 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