|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
rename file extension
I am trying for loop to rename file extension from .txt to .html :
as below : for i in *.txt; do mv "$i" `basename $i`.html; done ------------------------------------------- But this renames a file file1.txt as file1.txt.html anyone know how get avoid .html added after .txt ? it should rename file.txt as file.html and not file.txt.html Thanks in advance |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
The basename command gives the string after the last slash, try this: Code:
for i in *.txt; do mv "$i" "${i%.txt}".html; done |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Dear Franklin
what does this part "${i%.txt}".html mean ? the i% spesifically ? Thanks |
|
#4
|
|||
|
|||
|
Thanks Franklin!
Yahyaa - its a pattern defined to exclude changes before .txt - "${i%.txt}". Franklin - correct if i am wrong ... |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
Have a read of this tutorial regarding manipulating strings Regards |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| extract file extension using sed | r_praveenk | Shell Programming and Scripting | 7 | 09-09-2008 12:45 PM |
| Recursicely search and rename file extension | riverside | Shell Programming and Scripting | 7 | 04-11-2008 10:02 AM |
| How to get file extension | shirleyeow | Shell Programming and Scripting | 17 | 01-17-2008 07:40 AM |
| trim file name extension???? | vishal_ranjan | AIX | 1 | 07-31-2007 09:34 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 |
|
|