The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 02:08 PM
Renaming Files abch624 Shell Programming and Scripting 2 03-20-2008 12:54 AM
renaming files jxh461 UNIX for Dummies Questions & Answers 1 02-04-2008 09:32 PM
Renaming files Tygoon UNIX for Dummies Questions & Answers 7 01-06-2008 10:59 PM
renaming files raguramtgr UNIX for Dummies Questions & Answers 4 09-21-2004 10:57 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-23-2006
systemsb systemsb is offline
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
  #2 (permalink)  
Old 05-24-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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.
  #3 (permalink)  
Old 05-24-2006
systemsb systemsb is offline
Registered User
  
 

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

could you please explain to me what this means

. \( ! -name . -prune \)
  #4 (permalink)  
Old 05-25-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

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

Check this link - Non-recursive find
Sponsored Links
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 10:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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