Register
It is currently Mon Oct 20, 2014 11:23 pm

RENAMING FILES !!!! HELP!!!


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Dec 07, 2012 2:37 pm   

Joined: Fri Dec 07, 2012 2:31 pm
Posts: 1
Hi all,
Suppose I have a folder that has a bunch of files, all named XXXX_Fred_XXX.txt
... Here, the XXX's can be anything and of variable length.

How can I change all of the files from
XXXX_Fred_XXX.txt
to
XXXX_Tony_XXX.txt

I already know how to change file extensions (ex: .txt to .sh)
but how do I change a string of text that is in the middle of a file? --- And do it for multiple files at once?
Thanks!


Top
 Profile  
 PostPosted: Sat Dec 08, 2012 7:07 am   

Joined: Mon Sep 24, 2012 7:48 am
Posts: 5
Without trying it, this comes to mind:
Code:
for F in *_Fred_*.txt; do
    mv -v "$F" "$(echo $F | sed 's/_Fred_/_Tony_/')"
done


Top
 Profile  
 PostPosted: Tue Dec 11, 2012 9:41 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Without even using sed;
Code:
for F in *_Fred_*.txt; do
  mv "$F" "${F/_Fred_/_Tony_}"
done


DW


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP