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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rename several files at once

Status
Not open for further replies.

karacharlie

Programmer
Dec 19, 2004
14
DE
Hi,
I'd like to rename several files, but I know only one part of the name, e.g.
rename:
abc.x.y.z...
abc.1.2.3... (x,y,z,1,2,3 not known)
to
abc000.x.y.z...
abc000.1.2.3...

The problem is that I only know the <abc.> of the filenames, but not the rest of the file's name

Could anyone help?
Thanks
Charlie
 
This worked for me, but I'm sure others will have a better approach:

Code:
for i in `ls file*`                            
do                                             
  name1=`echo $i|awk -F . '{ print $1 '}`        
  name2=`echo $i|awk -F "$name1." '{ print $2 '}`
  newname=`echo $name1|awk '{ print $1 "000" '}` 
  mv $name1.$name2 $newname.$name2               
done
 
bash:
Code:
for file in abc.*; do
  echo mv $file ${file%%.*}000.${file#*.}
done

What about the answers you got to the (nearly) same thread in the awk forum?
(How to get the ID for ThreadNNN JS links?)

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
this
[ignore]
thread271-1013350
[/ignore]

results in this:
thread271-1013350

simply copy the thread id from the top of the thread and paste it - it becomes TGML "thingy" implicitely.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Found it, but time consuming translations of a few words for this (ex)post, and wush there was your post :) Its so unimposing under the title.

perl rename:
Code:
rename 's/\./000./' abc.*
# or crappy syntax
rename . 000. abc.*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top