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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Batch changing file extensions cdines Shell Programming and Scripting 5 05-19-2008 05:11 AM
Stripping out extensions when file has multiple dots in name Nemelis Shell Programming and Scripting 8 05-14-2008 08:12 AM
Truncate multiple file extensions prvnrk Shell Programming and Scripting 12 04-04-2008 10:20 AM
extensions inkastinka UNIX for Dummies Questions & Answers 3 05-19-2006 11:22 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 11-06-2001
thurrock thurrock is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 2
Post File name extensions

Hello people, I was wondering if anyone could help me?

I want to produce a shell script that changes the filename extension on all matching file.

E.G. change all files called ‘something.rtf’ to ‘something.doc’ by giving the command:


Changex rtf doc

*where ‘Changex’ is the name of my shell script.

Does anyone know how to do this or know what ‘functions’ I should use???

with regards,
nick

Last edited by thurrock; 11-06-2001 at 08:54 PM..
  #2 (permalink)  
Old 11-06-2001
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Code:
#! /usr/bin/ksh

old=$1
new=$2

for file in *.$old ; do
     mv $file ${file%$old}$new
done
exit 0
  #3 (permalink)  
Old 11-07-2001
thurrock thurrock is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 2
Smile thanks

fantastic - it works!!! - you are a genius!!!
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 02:22 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