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
The basename command gives the string after the last slash, try this:
for i in *.txt; do mv "$i" "${i%.txt}".html; done
yahyaaa
3
Dear Franklin
what does this part "${i%.txt}".html mean ? the i% spesifically ?
Thanks
Thanks Franklin!
Yahyaa - its a pattern defined to exclude changes before .txt - "${i%.txt}".
Franklin - correct if i am wrong ...
It strips the shortest match of ".txt" from back of $i.
Have a read of this tutorial regarding manipulating strings
Regards