hankknight
asked on
Changing extension and content for ALL files in a folder
Hello,
I use the following to change ALL extensions from .cgi to .pl.
It changes the filenames, AND it also changes the text inside of the files to reflect the changes.
It works awesome, but it ONLY adjusts the content of the .cgi files. Other files, like .html files and .js files are NOT changed to reflect the filename changes.
So, style.css and main.htm still point to the OLD extension, not the new one.
How can I change the extension name then change the content of ALL files to reflect the new extensions?
Thanks!
# Thanks, ravenpl
# https://www.experts-exchange.com/questions/22025115/Changing-extension-for-ALL-files-in-a-folder.html
cd destination/dir
find -type f -name '*.cgi' | while read file; do
BASE=$(basename "$file" .cgi)
DIR=$(dirname "$file")
DEST="$DIR/$BASE.pl"
[ -e "$DEST" ] && { echo "$DEST already exists, terminating"; exit 1; }
cat "$file" | sed "s/\.cgi/\.pl/g" > "$DIR/$BASE.pl"
done
#if verified all done fine
find -type f -name '*.cgi' -exec rm -fv {} \;
I use the following to change ALL extensions from .cgi to .pl.
It changes the filenames, AND it also changes the text inside of the files to reflect the changes.
It works awesome, but it ONLY adjusts the content of the .cgi files. Other files, like .html files and .js files are NOT changed to reflect the filename changes.
So, style.css and main.htm still point to the OLD extension, not the new one.
How can I change the extension name then change the content of ALL files to reflect the new extensions?
Thanks!
# Thanks, ravenpl
# https://www.experts-exchange.com/questions/22025115/Changing-extension-for-ALL-files-in-a-folder.html
cd destination/dir
find -type f -name '*.cgi' | while read file; do
BASE=$(basename "$file" .cgi)
DIR=$(dirname "$file")
DEST="$DIR/$BASE.pl"
[ -e "$DEST" ] && { echo "$DEST already exists, terminating"; exit 1; }
cat "$file" | sed "s/\.cgi/\.pl/g" > "$DIR/$BASE.pl"
done
#if verified all done fine
find -type f -name '*.cgi' -exec rm -fv {} \;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.