replace *.sqc files with *.sqC extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace *.sqc files with *.sqC extension
# 1  
Old 04-27-2004
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.

Last edited by rameshonline; 04-27-2004 at 05:44 PM..
# 2  
Old 04-27-2004
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  
Old 04-27-2004
Thanks djsal.... It works....

but I am wondernig whether we can do it in a line or not .... any idea
# 4  
Old 04-27-2004
Quote:
Originally posted by rameshonline
Thanks djsal.... It works....

but I am wondernig whether we can do it in a line or not .... any idea
sorry man, thats the only way I know how...
# 5  
Old 04-27-2004
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

on a single line, although it hampers readability....

That will rename all .c files to .cpp in the current directory.

Peace,
ZB
http://www.zazzybob.com
# 6  
Old 04-27-2004
I am still looking into using the registers for doing this but anyway Thanks for your help guys .... i learned two other ways....
# 7  
Old 04-28-2004
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command + replace the extension (.xxx) by *

Hello, I'm on HP Unix and in a Job, I tried to extract all files from a folder, and replace the extension (.xxxx) by '*' , remove duplicates and move the result in a file.. Example : Folder has : ABC, CCC.txt, CCC.sf, CCC.sfd, DDD I need to generate and output file with : ... (6 Replies)
Discussion started by: royinfo.alain
6 Replies

2. Shell Programming and Scripting

Listing files with an certain extension

I'm suppose to write a command that would list all files that end in .tx with an optional t at the end. So far all I got is listing the files that end in .tx which is: ls *.tx Now my problem is how do I add the optional t at the end. (3 Replies)
Discussion started by: Shawn565
3 Replies

3. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

4. Shell Programming and Scripting

Python - glob () - How to grep same files with different extension files

Hi I Have a directory and i have some files below abc.txt abc.gif gtee.txt ghod.pid umni.log unmi.tar How can use glob function to grep abc files , i have created a variable "text" and i assigned value as "abc", please suggest me how can we use glob.glob( ) to get the output as below... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

5. Shell Programming and Scripting

[Solved] Replace extension of filename stored in a variable

Hi there, I have a small question (most like a true beginners question :) ). In a script I have a filename stored in variable (vFile). Through the an input parameter this variable gets its value (for instance cookie.txt). Two new variables are created with the value of vFile, but with a... (2 Replies)
Discussion started by: rberkers
2 Replies

6. UNIX for Dummies Questions & Answers

How to list files with no extension together with *.prog files?

Hi, I know that to list files with no extension, we can use.. ls -1 | grep -v "\." And to list .prog files, we can use.. ls -1 *.prog or ls -1 | grep '.prog$' (4 Replies)
Discussion started by: adshocker
4 Replies

7. Shell Programming and Scripting

Replace file name extension in loop

Hi! I have this shell script that I need to finish. Currently I need to fix one line to make it work. I need to change a file extension. See this code, is pretty simple. #!/bin/sh # Extensions OLD_EXT=.flv NEW_EXT=.mp4 COUNT_FILES=$(ls -l *$OLD_EXT | grep ^- | wc -l) if ; then ... (8 Replies)
Discussion started by: pulsorock
8 Replies

8. UNIX for Dummies Questions & Answers

How to compress files without extension

Could someone please help? I'm trying to compress all the files in a directory without extension. I know for typical files with extension, the command is something like: tar -zcvf file.tar.gz *.doc What is the command for files without extension? Thanks. (4 Replies)
Discussion started by: AChan1118
4 Replies

9. UNIX for Dummies Questions & Answers

Checking files extension

Hi, I need one line command to display all files that ends with .scr. Example: In a directory I have 10 files, out of that 4 files have filetype extension .dat and 4 files with .scr and 2 files with .txt.... In this i want to display only files that ends with .scr. I tried some commands,... (2 Replies)
Discussion started by: gwgreen1
2 Replies

10. HP-UX

Files without extension

I am brand new to hp unix systems. I see some files without extension on this system. If I type name of the file it shows me so many detail but does not take me back to command prompt. What are these files and how do I come back to command prompt? Please help (1 Reply)
Discussion started by: rajahindustani
1 Replies
Login or Register to Ask a Question