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.