Requirement: 1. Create chinache_0726 (chinacache _ date) in the test database every day (I .e., chinacache _ date); 2. process the log file 13039_20100722_w3c according to the table structure
Requirement: 1. Create chinache_0726 (chinacache _ date) in the test database every day (I .e., chinacache _ date); 2. process the log file 13039_20100722_w3c according to the table structure
Requirements:
1. Create chinache_0726 (chinacache _ date) in the test database every day );
2. process the log file 13039_20100722_w3c according to the table structure and insert the result to the created table;
The awk function is not just a simple process of some data. After reading the following code, combined with shell, you will see a different awk
Code:
! /Usr/bin/awk-f
# Sh. awk
BEGIN {
"Date + % m % d" | getline today
Cdn = "chinacache"
System ("/usr/local/mysql/bin/mysql-uroot-proot test-e \" create table chinacache _ 'date + % m % d' (id int (20) not null AUTO_INCREMENT, code int (20), ip varchar (20), times int (20), cdn_name varchar (20), file varchar (256), url varchar (256 ), access_time varchar (30), primary key (id ))\"")
}
{
Split ($4, ,":")
B [$1 "" $7 "" $9 "" $11 "", a [2] ":" a [3] ++
}
END {
For (I in B ){
Split (I, c ,"")
Printf ("insert into '% s' (code, ip, times, cdn_name, file, url, access_time) values (' % s', '% s ', '% s',' % s'); \ n ", cdn" _ "today, c [3], c [1], B [I], cdn, c [2], c [4], c [5]);
}
}
Write the required code, and insert the data to the database table using shell:
./Sh. awk/data/log/13039_20100722_w3c |/usr/local/mysql/bin/mysql-uroot-proot test