The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rename a file name Aswarth Shell Programming and Scripting 0 06-04-2008 11:18 AM
Not able to rename file MANISH KU Shell Programming and Scripting 2 06-27-2007 01:07 AM
how to rename a file before and after a ftp? forevercalz Shell Programming and Scripting 2 10-28-2005 06:19 AM
Help with multiple file rename - change case of part of file name steve7 UNIX for Dummies Questions & Answers 7 06-30-2005 10:41 AM
rename in batch kathy18 Shell Programming and Scripting 3 03-09-2005 05:47 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2006
Registered User
 

Join Date: Jul 2006
Posts: 17
Stumble this Post!
rename the file in batch

In my dir there are files like

a.xml
b.xml
abnc.xml
12.abc.xml
12.anc.sfoioi.xml

I need to remove .xml from all the files

Is there any direct way without using any for/do loop

Right now i am using
for file in *
do
newfile=${file%.xml}
mv file $newfile
done

Please let me know if there is any direct way in one line without any loop
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-11-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,443
Stumble this Post!
for f in *.xml ; do mv $f ${f%.xml} ; done

gets it in one line...still a loop though.
Reply With Quote
  #3 (permalink)  
Old 12-11-2006
Registered User
 

Join Date: Dec 2006
Location: Maryland
Posts: 144
Stumble this Post!
ls -1| awk -F ".xml" '{print "mv ", $1".xml",$1}' | ksh

Check if it works.
Reply With Quote
  #4 (permalink)  
Old 12-12-2006
Registered User
 

Join Date: Jul 2006
Posts: 17
Stumble this Post!
thanks

hey kapilraj
that was really kool man ...

thanks a lot ...
Reply With Quote
  #5 (permalink)  
Old 12-12-2006
Registered User
 

Join Date: Dec 2006
Location: Maryland
Posts: 144
Stumble this Post!
That has a bug though it does'nt hurt.

A neat one would be

ls -1 *.xml | awk -F ".xml" '{print "mv ", $1".xml",$1}'
Reply With Quote
  #6 (permalink)  
Old 09-28-2007
Registered User
 

Join Date: Jul 2006
Posts: 17
Stumble this Post!
bash-2.03$ ls -1
TEST.xml.123
TEST2.ABC.xml
TEST2.ABC.xml.123
bash-2.03$

bash-2.03$ ls -1| awk -F".123" '{print $1}'
TEST
TEST2
TEST2
bash-


How can i get output as
TEST.xml
TEST2.ABC
TEST2.ABC.xml

even though i gave -F as .123 but it always take as . (not considering 123 after dot)
Reply With Quote
  #7 (permalink)  
Old 09-28-2007
Registered User
 

Join Date: Jul 2006
Posts: 17
Stumble this Post!
never mind, i use nawk instead of awk and it worked fine (i am using SUN OS)
oh HP awk worked fine
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0