]> Pileus Git - ~andy/sfvlug/blob - awk/src/vpaste.sh
Add sed and awk presentation
[~andy/sfvlug] / awk / src / vpaste.sh
1 #get param
2 awk -v "key=$1" '
3         BEGIN {RS=" "; FS="="}
4         $1 ~ key {print $2}
5 '
6
7 # cut file
8 bnd="${CONTENT_TYPE/*boundary\=/}"
9
10 awk -v "want=$1" -v "bnd=$bnd" '
11         BEGIN { RS="\r\n" }
12
13         # reset based on boundaries
14         $0 == "--"bnd""     { st=1; next; }
15         $0 == "--"bnd"--"   { st=0; next; }
16         $0 == "--"bnd"--\r" { st=0; next; }
17
18         # search for wanted file
19         st == 1 && $0 ~  "^Content-Disposition:.* name=\""want"\"" { st=2; next; }
20         st == 1 && $0 == "" { st=9; next; }
21
22         # wait for newline, then start printing
23         st == 2 && $0 == "" { st=3; next; }
24         st == 3             { print $0    }
25         # head
26 ' | head -c $((128*1024)) # Limit size to 128K
27
28 # List
29 awk -v 'rows=4' -v 'cols=60' '
30         FNR==1      { gsub(/.*\//, "", FILENAME);
31                       print FILENAME
32                       print "-----" }
33         FNR==1,/^$/ { next }
34         /\S/        { i++; printf "%."cols"s\n", $0 }
35         i>=rows     { nextfile  }
36         ENDFILE     { i=0; print ""  }
37 ' $(ls -t db/*)
38
39 # Stat
40 ls -l --time-style='+%Y %m' db |
41 awk -v 'hdr=Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec' '
42         BEGIN { printf "%64s\n", hdr }
43         NR>1  { cnt[$6+0][$7+0]++ }
44         END   { for (y in cnt) {
45                   printf "%4d", y
46                   for (m=1; m<=12; m++)
47                     printf "%5s", cnt[y][m]
48                   printf "\n" } }'