Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing filenames in a directory 1

Status
Not open for further replies.

Zugdud

IS-IT--Management
Feb 26, 2003
158
0
0
US
Howdy folks, is there a way to rename a directory full of files? i just need to remove the - out of the filename and chage the first letter (always a T) from upper case to lower case, so for example I want T-234 to be t234

This is on a redhat 9 linux system, thanks!
 
Well, sorry should have been more specific. Is there a command that will do groups of files at a time? Theres several thousand files to rename
 
A starting point:
ls T* | while read f
do mv $f $(echo $f | sed 's!^T!t!;s!-!!g')
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You don't mention what platform you're on, but many unices come with a 'rename' command that takes wild cards and patterns. Otherwise you'll have to script it like PHV suggests.
 
Cool hey, just tried it out and the system does indeed have the rename command. Just from fooling around with it alittle, it does seem pretty user friendly so even I can handle using it.

Thanks for the headsup!
 
In Awk:
[tt]
awk 'BEGIN {
for (i=1;i<ARGC;i++)
{ $0=ARGV
sub(/^T/,"t"); gsub(/-/,"")
cmd="mv " ARGV " " $0
system( cmd )
}
exit
}' T*
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top