convert all *. c files to *.cpp files in a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers convert all *. c files to *.cpp files in a directory
# 1  
Old 03-09-2010
convert all *. c files to *.cpp files in a directory

Hiiiii....

how to convert all *. c files to *.cpp files , in a directory given using shell script.

SmilieThnaking u.Smilie
# 2  
Old 03-09-2010
Here is the basic script

Code:
#!/bin/ksh
ls *.c >amit.temp

while read line

do
echo $line
new=${line}pp
echo $new
mv $line $new > /dev/null
echo "Renamed all c files to cpp files"
done < amit.temp

# 3  
Old 03-09-2010
Another approach:
Code:
ls *.c | awk '{system("mv "$0 " "$0 "pp")}'

# 4  
Old 03-09-2010
Hi,
Another version:
(if no space in file names)

Code:
for x in *.c;do mv $x ${x}pp;done

Best regards,
Lakris
# 5  
Old 03-09-2010
an xargs one

Code:
ls *.c | xargs -I{} mv {} {}pp

# 6  
Old 03-09-2010
Fine working wellll...then how to change the *.c file to *.h
# 7  
Old 03-09-2010
Quote:
Originally Posted by krishnampkkm
Fine working wellll...then how to change the *.c file to *.h
Back to awk for that one Smilie

Code:
ls *.c | awk -F. '{system("mv "$0 " " $1 ".h")}'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

2. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

3. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

4. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

5. Shell Programming and Scripting

Convert directory of text files to Unix/Linux Line Ending

I need help converting a directory of *.txt with Windows line ending to UTF-8 character encoding and Unix/Linux line ending. (9 Replies)
Discussion started by: chipperuga
9 Replies

6. Shell Programming and Scripting

Apply 'awk' to all files in a directory or individual files from a command line

Hi All, I am using the awk command to replace ',' by '\t' (tabs) in a csv file. I would like to apply this to all .csv files in a directory and create .txt files with the tabs. How would I do this in a script? I have the following script called "csvtabs": awk 'BEGIN { FS... (4 Replies)
Discussion started by: ScKaSx
4 Replies

7. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

8. Programming

Compiling multiple cpp files (abstract factory pattern)

Hi all, I have been working with java for awhile and because of my school projects I needed to switch C++. I tried to implement some patterns in C++ but unfortunately I couldn't. Specifically, I tried to implement abstract factory pattern but since I used separated files (habitual behavior from... (4 Replies)
Discussion started by: SaTYR
4 Replies

9. Shell Programming and Scripting

convert cpp program to c shell script ?

Hi guys I tried to convert this c++ code to c shell script but there are some bugs and I don't know how to solve it. This code prints the three variables in decreasing order: int main() { int x,y,z; cin >> x >> y >>z; if ( x < y ) if ( x < z ) if ( y < z ) cout << x <<" " <<... (2 Replies)
Discussion started by: domain
2 Replies
Login or Register to Ask a Question