例子:
$cat data.txt
SCN THREAD OPERATION ID OBJECT ID OBJECT NAME REPLICATE OPERATION SQL
------------- ------- -------------------------------------------------- ----------- ------------------------------- ---------- --------------- -------------------------------------------------
959936598838 1 0x00df.80ae1336.0000:0001.001087a6.00074e62.0010 0 N/A NO START set transaction read write;
959936598838 1 0x00df.80ae1336.0000:0001.001087a6.00074e62.0010 8144610 HEARTBEAT YES INSERT insert into "SRS"."HEARTBEAT"("INST_NAME","CR_DATE") values ('LIVE LIVE-22.',TO_DATE('03/15/2019 23:00:05', 'MM/DD/YYYY HH24:MI:SS'));
959936598839 1 0x00df.80ae1337.0000:0001.001087a6.00074e63.0174 0 N/A NO COMMIT commit;
从上面的文件中,是否可以使用 shell 脚本提取包含值的插入查询?
我需要如下所示的所需输出。
插入 "SRS"."HEARTBEAT"("INST_NAME","CR_DATE") 值 ('LIVE LIVE-22.',TO_DATE('03/15/2019 23:00:05', 'MM/DD/YYYY HH24 :错过'));
答案1
假设前七列没有空间。
$ while read a b c d e f g query; do echo "${query}"; done < data.txt | grep -Ei "insert|update"
insert into "SRS"."HEARTBEAT"("INST_NAME","CR_DATE") values ('LIVE LIVE-22.',TO_DATE('03/15/2019 23:00:05', 'MM/DD/YYYY HH24:MI:SS'));
$ awk '/insert|update/{for(i=1;i<=7;i++){$i=""}print}' data.txt
insert into "SRS"."HEARTBEAT"("INST_NAME","CR_DATE") values ('LIVE LIVE-22.',TO_DATE('03/15/2019 23:00:05', 'MM/DD/YYYY HH24:MI:SS'));