Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

  2. #2
    Just Joined!
    Join Date
    Oct 2004
    Posts
    62
    Hi mukesh941,
    From the folder where your sources are...
    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
    To be run from the aforementioned folder...
    Code:
    bash split_into_folders.sh
    As you can see the script makes a copies in subfolders called
    cDir, cppDir, hDir, objDir.
    After testing the copy you can use mv...
    Example of output (run from the Dir Forums):
    Code:
    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 added sh because I keep only c or sh sources
    (I don't use C++ and I include only standard h files).
    Bye

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...