The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 04-19-2007
ghostdog74 ghostdog74 is offline
Registered User
 

Join Date: Sep 2006
Posts: 1,434
Code:
#!/bin/sh
awk -v user="user1" ' BEGIN {  path = " /home/" user "/";command = "ls" path ;
              while ( (command | getline line)>0 ) {                          
                            if (line ~ /\....$/) {
                                          ext = substr(line,length(line)-2)
                                          Extension[ext]    
                                          files[line] = ext
                            }                            
              }
            }
        END {   makedircmd = "mkdir "
                for ( e in Extension) {
                     print "making " path e                     
                     dir = path e
                     makedircmd = makedircmd dir                                      
                     print makedircmd
                 }
                 #system(makedircmd) #uncomment to use
                 for (f in files) {
                            mvcmd = "mv" path f " " path files[f]
                            traceback = "mv" path files[f] "/" f path 
                            print traceback
                            print traceback >> "backup.sh" #backup
                            #system(mvcmd) #uncomment to use
                 }
        }

' "file"
an attempt in awk. you can use backup.sh to move back those files to original directory.
Reply With Quote