[20191202]awk使用陣列技巧.txt

lfree發表於2019-12-02

[20191202]awk使用陣列技巧.txt

--//參考連線:

$ cd /u01/app/11.2.0/grid/rdbms/audit
$ ls -ltr|grep   "^-" |awk '{print $6 " " $5 }'| awk ' {  arr[$1]+=$2 ; freq[$1]++ } END {for (key in arr) printf "%20s\t%20s\t%20s\n", key, arr[key] ,freq[key] }' | sort
$ ls -ltr|grep   "^-" |awk '{print $6 " " $5 }'| awk ' {  arr[$1]+=$2 ; freq[$1]++ } END {for (key in arr) printf "%20s\t%20s\t%20s\n", key, arr[key] ,freq[key] }' | sort | head
          2016-12-24                     749                       1
          2019-09-02                   52600                      70
          2019-09-03                   72126                      96
          2019-09-04                   72136                      96
          2019-09-05                   72136                      96
          2019-09-06                   72128                      96
          2019-09-07                   75150                     100
          2019-09-08                   72134                      96
          2019-09-09                   72142                      96
          2019-09-10                   71376                      95

--//注意我ls的別名與別人定義不同:
$ alias ls
alias ls='ls --color=auto --time-style=+"%Y-%m-%d %H:%M:%S"'

--//再修改一下:

$ ls -ltr|grep   "^-" | awk ' {  arr[$6]+=$5 ; freq[$6]++ } END {for (key in arr) printf "%20s\t%20s\t%20s\n", key, arr[key] ,freq[key] }' | sort | head
          2016-12-24                     749                       1
          2019-09-02                   52600                      70
          2019-09-03                   72126                      96
          2019-09-04                   72136                      96
          2019-09-05                   72136                      96
          2019-09-06                   72128                      96
          2019-09-07                   75150                     100
          2019-09-08                   72134                      96
          2019-09-09                   72142                      96
          2019-09-10                   71376                      95


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2666438/,如需轉載,請註明出處,否則將追究法律責任。

相關文章