我需要在查询日志中的所有select语句中单独查找所有表名。有没有办法grep
(或)任何其他选项,以便在我的文件中的单词FROM
之后立即获取字符串..
示例:file
包含类似
select a, b, c FROM `table1` join `table2` etc...
insert into.................
commit
select * FROM `tablex` ..............
select y,s,h FROM `tabley`.................
.
.
.
现在我只想从select stmts中选择不同的表。即,
table1
tablex
tabley
答案 0 :(得分:0)
我不确定我是否理解正确但如果你想提取'from'之后的第一个单词,你可以尝试这样的事情:
➜ tmp cat log
select id, name from account where name = 'John';
select * from price where id > 0;
➜ tmp cat log | gawk -F'from ' '{print $2}' | gawk '{print $1}'
account
price
➜ tmp
如果您还要打印已连接表格的名称,则需要对其进行扩展。