#4 useful shell statistic function: x sf adf scf. in tool_cmd.sh // My English is poor.
Use these shell function, I'm rarely need to write awk script for daily use.
Use these shell function, you can write the complex data process shell very fast, in several seconds.
Then you can do other things or just wait the result.
content of the example file, apache log:
127.0.0.1 - - [24/Nov/2012:20:18:12 +0800] "GET / HTTP/1.1" 304 -
127.0.0.1 - - [24/Nov/2012:20:18:12 +0800] "GET /favicon.ico HTTP/1.1" 404 209
127.0.0.1 - - [24/Nov/2012:20:18:14 +0800] "GET / HTTP/1.1" 304 -
127.0.0.1 - - [24/Nov/2012:20:18:14 +0800] "GET /favicon.ico HTTP/1.1" 404 209
the 1st column in file:
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.1
2nd column in file with columns splited by '/' :
Nov
Nov
Nov
Nov
last column and third column in file:
- -
209 -
- -
209 -
column before last in file:
304
404
304
404
99th column (maybe not exist) in stdin:
(4 EMPTY row)
9th column with value *2 in file:
608
808
608 808
-1
208
-1
208
count of 1st column appear times in $file: // use the example data of apache log.
127.0.0.1 4
count of 1st and 7th column appear times in stdin:
127.0.0.1 / 2
127.0.0.1 /favicon.ico 2
count of 2nd column which splited by '"' appear times in $file:
GET / HTTP/1.1 2
GET /favicon.ico HTTP/1.1 2
// this example was translate to awk form.
adf $file 2 10 => awk '{num[$2]+=$10} END{for (i in num) print i, num[i]}' $file
adf $file '2 (NF-1)' '9*2' => awk '{num[$2" "$(NF-1)]+=$9*2} END{for (i in num) print i, num[i]}' $file
scf(), like the "join" command, but you can specify multi column(in any order) for the SAMEKEY between 2 file.
FILE1:
Louix M 10085 Beijing
FILE2:
10085 Louix China
If you want the whole line of two file in one line, while 1st 3rd column in file1 is equal 2nd 1st column in file2:
Louix Gu 10085 Beijing 10085 Louix China
It's a little noisy, we just want the first name(1st column in file1) and country(2nd column in file2), use:
Louix China