我有一个很大的mysql通用查询日志,如下所示:
110301 2:19:29 268341 Query SELECT option_value FROM wp_options WHERE option_name = 'sidebars_widgets' LIMIT 1
268341 Query SELECT autoload FROM wp_options WHERE option_name = 'rewrite_rules'
268341 Query DELETE FROM wp_options WHERE option_name = 'rewrite_rules'
268341 Query SELECT option_value FROM wp_options WHERE option_name = 'rewrite_rules' LIMIT 1
268341 Query SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category') ORDER BY t.name ASC
268341 Query SELECT ID, post_name, post_parent FROM wp_posts WHERE post_type = 'page'
268341 Query SELECT * FROM wp_posts WHERE ID = 9191 LIMIT 1
268341 Query SELECT ID, post_name, post_parent FROM wp_posts WHERE post_type = 'attachment' AND post_parent = 9191
268341 Query SELECT * FROM wp_posts WHERE ID = 8805 LIMIT 1
我想使用AWK查找所有INSERT INTO语句?
答案 0 :(得分:2)
gawk "/INSERT INTO/" query.log
我估计你会做额外的处理,否则如前所述,你真的不需要awk。
答案 1 :(得分:1)
为什么选择awk? grep更适合。
grep -i "INSERT INTO" filename.log
答案 2 :(得分:0)
我会使用带-o选项的grep:
$ #with your input in /tmp/file
$ grep -O 'SELECT .*' /tmp/file
SELECT option_value FROM wp_options WHERE option_name = 'sidebars_widgets' LIMIT 1
SELECT autoload FROM wp_options WHERE option_name = 'rewrite_rules'
SELECT option_value FROM wp_options WHERE option_name = 'rewrite_rules' LIMIT 1
SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category') ORDER BY t.name ASC
SELECT ID, post_name, post_parent FROM wp_posts WHERE post_type = 'page'
SELECT * FROM wp_posts WHERE ID = 9191 LIMIT 1
SELECT ID, post_name, post_parent FROM wp_posts WHERE post_type = 'attachment' AND post_parent = 9191
SELECT * FROM wp_posts WHERE ID = 8805 LIMIT 1