The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 02:18 PM
Not able to rename file MANISH KU Shell Programming and Scripting 2 06-27-2007 04:07 AM
how to rename a file before and after a ftp? forevercalz Shell Programming and Scripting 2 10-28-2005 09:19 AM
Help with multiple file rename - change case of part of file name steve7 UNIX for Dummies Questions & Answers 7 06-30-2005 01:41 PM
rename in batch kathy18 Shell Programming and Scripting 3 03-09-2005 09:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-11-2006
reldb reldb is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
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
  #2 (permalink)  
Old 12-11-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
for f in *.xml ; do mv $f ${f%.xml} ; done

gets it in one line...still a loop though.
  #3 (permalink)  
Old 12-12-2006
kapilraj kapilraj is offline
Registered User
  
 

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

Check if it works.
  #4 (permalink)  
Old 12-12-2006
reldb reldb is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
thanks

hey kapilraj
that was really kool man ...

thanks a lot ...
  #5 (permalink)  
Old 12-12-2006
kapilraj kapilraj is offline
Registered User
  
 

Join Date: Dec 2006
Location: Maryland
Posts: 162
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}'
  #6 (permalink)  
Old 09-28-2007
reldb reldb is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
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)
  #7 (permalink)  
Old 09-28-2007
reldb reldb is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
never mind, i use nawk instead of awk and it worked fine (i am using SUN OS)
oh HP awk worked fine
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0