Results 1 to 2 of 2
Hi m new learner to shell scripting
can any one give me idea to make a shell script that will differentiate all the .c, .cpp, .h, and .obj files from ...
- 02-12-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 2
differentiate all the .c, .cpp, .h, and .obj files from a folder and put it in diffe
Hi m new learner to shell scripting
can any one give me idea to make a shell script that will differentiate all the .c, .cpp, .h, and .obj files from a folder and put it in different corresponding folders.
Thanks
- 02-12-2009 #2Just Joined!
- Join Date
- Oct 2004
- Posts
- 62
Hi mukesh941,
From the folder where your sources are...
To be run from the aforementioned folder...Code:# split_into_folders.sh for i in c cpp h obj ; do mkdir "$i"Dir 2>/dev/null # instead of testing for the presence of folders echo "$i"Dir echo '--------------' ls -1 "$i"Dir/*."$i" 2>/dev/null cp *.$i "$i"Dir 2>/dev/null # mv *.$i "$i"Dir 2>/dev/null echo '====================================' done
As you can see the script makes a copies in subfolders calledCode:bash split_into_folders.sh
cDir, cppDir, hDir, objDir.
After testing the copy you can use mv...
Example of output (run from the Dir Forums):
I added sh because I keep only c or sh sourcesCode:cDir -------------- cDir/cflow.c ==================================== shDir -------------- shDir/loops.sh shDir/pepe.sh shDir/PTH.sh shDir/SimpleQuery.sh shDir/split_into_folders.sh shDir/sum2.sh shDir/sum3.sh shDir/sum4.sh shDir/sum.sh ==================================== cppDir -------------- ==================================== hDir -------------- ==================================== objDir -------------- ===================================
(I don't use C++ and I include only standard h files).
Bye


Reply With Quote