当前位置: 技术问答>linux和unix
查找文件里的信息
来源: 互联网 发布时间:2016-10-29
本文导语: 比如一个文本文件test是这样的: ----------- BEGIN /*!*/; # at 51315 #101210 16:22:36 server id 1 end_log_pos 51343 Intvar SET INSERT_ID=328/*!*/; # at 51343 #101210 16:22:36 server id 1 end_log_pos 51548 Query thread_id=835 ...
比如一个文本文件test是这样的:
-----------
BEGIN
/*!*/;
# at 51315
#101210 16:22:36 server id 1 end_log_pos 51343 Intvar
SET INSERT_ID=328/*!*/;
# at 51343
#101210 16:22:36 server id 1 end_log_pos 51548 Query thread_id=835 exec_time=0 error_code=0
SET TIMESTAMP=1291969356/*!*/;
INSERT INTO order_size_amount (order_id, amount, rule_id, size_id, company_id, member_id) VALUES ('499', '3', 153, '311', '36', '63')
/*!*/;
# at 51548
#101210 16:22:36 server id 1 end_log_pos 51575 Xid = 11333
COMMIT/*!*/;
# at 51575
#101210 16:22:36 server id 1 end_log_pos 51652 Query thread_id=835 exec_time=0 error_code=0
SET TIMESTAMP=1291969356/*!*/;
BEGIN
/*!*/;
# at 51652
#101210 16:22:36 server id 1 end_log_pos 51680 Intvar
SET INSERT_ID=154/*!*/;
# at 51680
#101210 16:22:36 server id 1 end_log_pos 51908 Query thread_id=835 exec_time=0 error_code=0
SET TIMESTAMP=1291969356/*!*/;
INSERT INTO order_rule (assembly_id, per_size, memo, order_id, order_amount_desc_id, company_id, member_id) VALUES ('347', '11', '', '499', 115, '36', '63')
/*!*/;
# at 51908
#101210 16:22:36 server id 1 end_log_pos 51935 Xid = 11334
COMMIT/*!*/;
------------------------
我想查找 order_size_amount,
grep "order_size_amount" test
INSERT INTO order_size_amount (order_id, amount, rule_id, size_id, company_id, member_id) VALUES ('499', '3', 153, '311', '36', '63')
但是我不值查找这一个,想找到的结果是
SET TIMESTAMP=1291969356/*!*/;
INSERT INTO order_size_amount (order_id, amount, rule_id, size_id, company_id, member_id) VALUES ('499', '3', 153, '311', '36', '63')
把他的前一条也显示出来.该怎么做?
-----------
BEGIN
/*!*/;
# at 51315
#101210 16:22:36 server id 1 end_log_pos 51343 Intvar
SET INSERT_ID=328/*!*/;
# at 51343
#101210 16:22:36 server id 1 end_log_pos 51548 Query thread_id=835 exec_time=0 error_code=0
SET TIMESTAMP=1291969356/*!*/;
INSERT INTO order_size_amount (order_id, amount, rule_id, size_id, company_id, member_id) VALUES ('499', '3', 153, '311', '36', '63')
/*!*/;
# at 51548
#101210 16:22:36 server id 1 end_log_pos 51575 Xid = 11333
COMMIT/*!*/;
# at 51575
#101210 16:22:36 server id 1 end_log_pos 51652 Query thread_id=835 exec_time=0 error_code=0
SET TIMESTAMP=1291969356/*!*/;
BEGIN
/*!*/;
# at 51652
#101210 16:22:36 server id 1 end_log_pos 51680 Intvar
SET INSERT_ID=154/*!*/;
# at 51680
#101210 16:22:36 server id 1 end_log_pos 51908 Query thread_id=835 exec_time=0 error_code=0
SET TIMESTAMP=1291969356/*!*/;
INSERT INTO order_rule (assembly_id, per_size, memo, order_id, order_amount_desc_id, company_id, member_id) VALUES ('347', '11', '', '499', 115, '36', '63')
/*!*/;
# at 51908
#101210 16:22:36 server id 1 end_log_pos 51935 Xid = 11334
COMMIT/*!*/;
------------------------
我想查找 order_size_amount,
grep "order_size_amount" test
INSERT INTO order_size_amount (order_id, amount, rule_id, size_id, company_id, member_id) VALUES ('499', '3', 153, '311', '36', '63')
但是我不值查找这一个,想找到的结果是
SET TIMESTAMP=1291969356/*!*/;
INSERT INTO order_size_amount (order_id, amount, rule_id, size_id, company_id, member_id) VALUES ('499', '3', 153, '311', '36', '63')
把他的前一条也显示出来.该怎么做?
|
grep -C1 "order_size_amount" test
试试
试试