我需要在查询日志中的所有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

最佳答案

我不确定我是否正确理解您的意思,但是如果您想提取“ 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


如果还要打印联接表的名称,则需要扩展它。

关于linux - 在linux系统中,如何找到文件中给定单词旁边的单词(紧接在旁边)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41059405/

10-11 04:17
查看更多