![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| change file extension from root and subdirectories | Astrid | Shell Programming and Scripting | 10 | 02-17-2008 07:18 AM |
| extension problem please help | sharmasdeepti | UNIX for Dummies Questions & Answers | 1 | 10-24-2007 07:29 AM |
| without extension | adurga | UNIX for Dummies Questions & Answers | 3 | 07-02-2007 12:34 PM |
| Changing extension | mohan705 | Shell Programming and Scripting | 4 | 06-30-2007 01:06 PM |
| how do i change extension | kswaraj | Shell Programming and Scripting | 2 | 06-28-2004 08:07 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
How do you write a shell script that change the extension of all the files?
e.g chext rtf doc where .rtf is the original extension and .doc is the new extension is it something to do with basename? do I need a for loop? Please help! Unix SuperNewbie |
|
||||
|
you will realize that making a search on these forums would give you more ideas... for exampe I searched for "rename files" and I got this link...
Easy way to mass rename files? I have just modified a small piece of code from the above link... Quote:
Vishnu. |
|
||||
|
I can get the script working as follows:
#!/bin/sh for name in `ls *.rtf` do name1=` echo $name| cut -f 1 -d . ` mv $name1.rtf $name1.doc done is working fine, but how do I make it work like this: chext 1 2 where 1 is the original extension and 2 is the desire new extension? |
|
||||
|
replace those "rtf" and "doc" with $1 and $2 in your script...
I should add that the above way using "cut" will not work if you have multiple dots in your filename... Code:
#!/bin/sh for name in `ls *.$1` do name1=`echo $name | sed -e "s/^\(.*\)\.$1$/\1\.$2/g"` mv $name $name1 done Code:
#!/bin/sh ls *.$1 | sed -e "s/^\(.*\)\.$1$/\1\.$1 \1\.$2/g" | xargs -n 2 mv -f Vishnu. |
|
||||
|
thanks vishnu!!
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|