|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I want to know if it it possible to change a filename extention to
another one using a shell script. eg. Reading a foo.c file and renaming it to foo.cpp using a script and this is read using a for loop, so say $i=foo.c, now the $i has to be changed to get foo.cpp. I've been able to do it using 'basename' is there some other way to do it? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
sid wrote:
> I want to know if it it possible to change a filename extention to > another one using a shell script. eg. Reading a foo.c file and > renaming it to foo.cpp using a script and this is read using a for > loop, so say $i=foo.c, now the $i has to be changed to get foo.cpp. > I've been able to do it using 'basename' is there some other way to do > it? Please provide sample input and expected output. -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
sid wrote:
> I want to know if it it possible to change a filename extention to > another one using a shell script. eg. Reading a foo.c file and > renaming it to foo.cpp using a script and this is read using a for > loop, so say $i=foo.c, now the $i has to be changed to get foo.cpp. > I've been able to do it using 'basename' is there some other way to do > it? I would do this in bash: for f in *.c; do mv "$f" "${f%.c}".cpp; done Hermann |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 2008-03-24, sid wrote:
> I want to know if it it possible to change a filename extention to > another one using a shell script. eg. Reading a foo.c file and > renaming it to foo.cpp using a script and this is read using a for > loop, so say $i=foo.c, now the $i has to be changed to get foo.cpp. > I've been able to do it using 'basename' is there some other way to do > it? Since all you need to do is add 'pp': mv "$i" "${i}pp" If you want to change any extension to '.cpp': mv "$i" "${i%.*}.cpp" -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
![]() |
| Outils de la discussion | |
|
|