LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-09-2012, 02:37 AM   #1
ksushants
LQ Newbie
 
Registered: Apr 2009
Posts: 10

Rep: Reputation: 0
Renaming files


Hi All,

I have a requirement to rename files:
Here we have to change the tco.out files to acw.out.

For E.G.: detco011tco.out should be renamed as deacw011.out.The other countries are FR,GB,ES,IT,NL &BE.

I have done it by:
a=detco011tco.out
x=`echo $a |cut -c1,2`
y=`echo $a |cut -c6-8`
z=`echo $a |cut -c12-15`
b=$x'acw'$y$z
mv $a $b

Is there any better and simpler way to do it? single command using SED?
 
Old 03-09-2012, 02:45 AM   #2
TKH
Member
 
Registered: Jul 2011
Location: Milky Way
Distribution: Ubuntu, LFS, Slackware, Fedora
Posts: 218

Rep: Reputation: 20
Correct me if I'm wrong, as I am not sure that I understand your question very well.
I think that you can do it by:
A=detco011tco.out mv $A $(echo $A | sed 's/tco.out/.out/')
 
Old 03-09-2012, 02:58 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Like TKH, I'm not entirely clear about your wishes.

Assuming this is your input:
Code:
# ls -l
total 0
-rw-r----- 1 druuna internet 0 Mar  9 08:54 betco033tco.out
-rw-r----- 1 druuna internet 0 Mar  9 08:54 detco011tco.out
-rw-r----- 1 druuna internet 0 Mar  9 08:54 nltco022tco.out
Running this code:
Code:
for THISFILE in *tco.out; do mv $THISFILE $(echo ${THISFILE/tco/acw} | sed 's/tco//'); done
You will end up with this:
Code:
$ ls -l
total 0
-rw-r----- 1 druuna internet 0 Mar  9 08:54 beacw033.out
-rw-r----- 1 druuna internet 0 Mar  9 08:54 deacw011.out
-rw-r----- 1 druuna internet 0 Mar  9 08:54 nlacw022.out
betco033tco.out changes to beacw033.out (first tco is changed to acw, second tco is removed).

Hope this helps.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming Files..Help npeddle Linux - Newbie 9 12-20-2010 03:17 PM
Help with renaming files EchoPhyber Linux - Newbie 4 03-26-2010 09:38 AM
help renaming files please balistic Linux - Newbie 2 07-29-2007 04:35 PM
Renaming files TomalakBORG Linux - Newbie 2 12-05-2005 05:13 PM
Renaming files in one go saurya_s Linux - Software 1 01-12-2004 02:16 PM


All times are GMT -5. The time now is 04:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration