LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   renaming file extensions (https://www.linuxquestions.org/questions/linux-newbie-8/renaming-file-extensions-596176/)

mike_stlouis 10-31-2007 04:48 PM

renaming file extensions
 
i understand WHY this will not work, and i see many scripts on-line that do ALMOST the same thing, but not quite....
i want to rename all the files with exentsion: .bas-new to simply: .bas
how can i do that.
# called like: ./rename_script.sh *.bas-new
#!/bin/bash

for filename in "$@";
do
rename *.bas-new *.bas
done

bigrigdriver 10-31-2007 05:22 PM

Part of the Pleasure of Linux is the challange. So here's the challenge. Study the use of grep and sed, and their use in a bash script.

Then, in your sudo code, change
Quote:

do
rename *.bas-new *.bas
done
to
Quote:

do
grep bas.new # to select only those lines with the regular expression bas.new
sed -e <substitute /bas.new/bas/g> # to change bas.new to bas
done

gilead 10-31-2007 05:28 PM

Have a look at the man page for rename (if your distro provides it). You could do something like:
Code:

rename 'bas-new' 'bas' *bas-new


All times are GMT -5. The time now is 03:33 PM.