Last active
October 7, 2021 15:17
-
-
Save nasirkhan/6990046 to your computer and use it in GitHub Desktop.
Remove file extension using the linux shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
#!/bin/sh | |
for file in `ls *.html` | |
do | |
newname=`echo $file|sed 's/\.html$//g'` | |
mv $file $newname | |
done | |
``` |
newname="${file//.html}"
So shorter:
ls *.html | while read file
do
mv "${file}" "${file//.html}"
done
This is a really good reference to learn more about bash : https://tldp.org/LDP/abs/html/
About string manipulation : https://tldp.org/LDP/abs/html/string-manipulation.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice, but if you extend it a little bit it might be better
!/bin/sh
extension = '.html'
for file in
ls *${extension}
do
newname=
echo $file|sed 's/\${extension}$//g'
mv $file $newname
done
this should work, not tested.