Skip to content

Instantly share code, notes, and snippets.

@sriramster
Created October 29, 2013 11:39
Show Gist options
  • Save sriramster/7213127 to your computer and use it in GitHub Desktop.
Save sriramster/7213127 to your computer and use it in GitHub Desktop.
Awk stuffs, tried to categorize the ~/Downloads folder inside $HOME.
function _categorize(type,dir) {
matches = ($9 ~ type)
if(matches) {
nlines++
if(dir) {
query = sprintf("cp %s %s",$9,dir)
system(query)
}
}
}
BEGIN {
nlines = 0
_pattern[1,1]="[*\\.]pdf"
_pattern[1,2]="~/personal/pdf/"
_pattern[2,1]="[*\\.]zip"
_pattern[2,2]="~/personal/zip/"
_pattern[3,1]="[*\\.]tar[.]gz"
_pattern[3,2]="~/personal/tars/"
}
{
_categorize(_pattern[1,1],_pattern[1,2])
_categorize(_pattern[2,1],_pattern[2,2])
_categorize(_pattern[3,1],_pattern[3,2])
}
END {
print nlines
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment