The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help renaming files bbbngowc UNIX for Dummies Questions & Answers 5 04-23-2008 11:08 AM
Renaming Files abch624 Shell Programming and Scripting 2 03-19-2008 08:54 PM
renaming files jxh461 UNIX for Dummies Questions & Answers 1 02-04-2008 05:32 PM
Renaming files Tygoon UNIX for Dummies Questions & Answers 7 01-06-2008 06:59 PM
renaming files raguramtgr UNIX for Dummies Questions & Answers 4 09-21-2004 07:57 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-23-2006
Registered User
 

Join Date: Jan 2006
Posts: 23
renaming files

directory name = /usr/tom/1997

files -
ABC_1997_ST1_BCD.SQL
BCD_1997_ST1_EFG_SAB.SQL
TTT_EBC_1997_ST1_A.SQL

sub directory - /usr/tom/1997/jan

a) I want to just rename the all files ending with '.SQL' and also its contents in the 1997 directory(excluding subdirectories eg '/usr/tom/1997/jan) like

ABC_1997_ST1_BCD.SQL to ABC_1997_ST2_BCD.SQL
(also change the any 1997_ST1 TO 1997_ST2 within the file as well)

BCD_1997_ST1_EFG_SAB.SQL to BCD_1997_ST2_EFG_SAB.SQL
(also change the any 1997_ST1 TO 1997_ST2 within the file as well)

TTT_EBC_1997_ST1_A.SQL to TTT_EBC_1997_ST2_A.SQL
(also change the any 1997_ST1 TO 1997_ST2 within the file as well)

i was able to change the file contents but not the filename.Also the folowing
script changes even the subdirectories which i do not want

list=`ls`
for i in $list
do
sed -n '/[sS][Tt]1/p' ${i}
done
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-23-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
see this

Go to the 1997 directory.

Code:
cd /usr/tom/1997
for i in `find . \( ! -name . -prune \) -name "*.SQL"`
do
 fname=$(basename ${i})
 sed 's/^\(.*\)_[Ss][Tt]1_\(.*\)$/\1_ST2_\2/g' ${fname} >${fname}.tmp
 newfilename=$(echo $fname | sed 's/^\(.*\)_[Ss][Tt]1_\(.*\)$/\1_ST2_\2')
 mv ${fname}.tmp $newfilename
 rm -f $i
done
Hope this gives you some idea.
Reply With Quote
  #3 (permalink)  
Old 05-24-2006
Registered User
 

Join Date: Jan 2006
Posts: 23
Thanks for the reply

could you please explain to me what this means

. \( ! -name . -prune \)
Reply With Quote
  #4 (permalink)  
Old 05-24-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
check this

Check this link - Non-recursive find
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0