![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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
|
|
||||
|
check this
Check this link - Non-recursive find
|
| Sponsored Links | ||
|
|