![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get files with a specific extension | janavenki | Shell Programming and Scripting | 9 | 11-27-2007 05:56 PM |
| Feedback: Allow tar.gz extension for files | DukeNuke2 | Post Here to Contact Site Administrators and Moderators | 2 | 08-29-2007 10:22 AM |
| Removing the extension and FTP the files | pradkumar | Shell Programming and Scripting | 1 | 02-14-2007 11:01 AM |
| How to test for files with a particular extension. | jyotipg | UNIX for Dummies Questions & Answers | 1 | 05-09-2002 04:04 AM |
| How to list files will no extension | Wing m. Cheng | UNIX for Dummies Questions & Answers | 5 | 02-21-2002 11:34 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
replace *.sqc files with *.sqC extension
Hi everyone,
I want to know how to replace file extensions. For example how do i go about replacing all *.c files in a directory to *.cpp I think we can do it either with "find" commad or with special registers. I tried to use the following command mv \(.*\).c \1.cpp but it is giving an error saying, cant stat source (.*).c whats wrong with this ? I am not sure how to do it with find commnad. please let me know if anyone of you know how to do it.
__________________
Ramesh Last edited by rameshonline; 04-27-2004 at 01:44 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
This will do the trick!
#Korn shell or Bash for list in `ls -1t *.c*` do prefix=`echo $list | awk -F"\." '{print $1}'` mv $list ${prefix}.cpp done |
|
#3
|
|||
|
|||
|
Thanks djsal.... It works....
but I am wondernig whether we can do it in a line or not .... any idea
__________________
Ramesh |
|
#4
|
|||
|
|||
|
Quote:
|
|
#5
|
||||
|
||||
|
Still requires multiple commands, but in the Korn shell, you can do
Code:
for file in *.c; do _file=${file%%.c}.cpp; mv $file $_file; done
That will rename all .c files to .cpp in the current directory. Peace, ZB http://www.zazzybob.com |
|
#6
|
|||
|
|||
|
I am still looking into using the registers for doing this but anyway Thanks for your help guys .... i learned two other ways....
__________________
Ramesh |
|
#7
|
|||
|
|||
|
one other interesting way to do it
Hi Guys ...I found one other way of doing it. Try this
ls *.c | awk -F '.' '{print "mv "$1".c "$1".cpp"}'| csh It does the trick. Thanks
__________________
Ramesh |
|||
| Google The UNIX and Linux Forums |