如何删除除包含TRUNCATE-INSERT的行以外的所有行 [英] How to delete all lines except lines that include TRUNCATE - INSERT

查看:77
本文介绍了如何删除除包含TRUNCATE-INSERT的行以外的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个脚本,将所有PL/SQL文件格式化为一个具有成对值的简单文件,这很难解释,我认为如果只看一下该文件就会更容易;

I have created a script that formats all of my PL/SQL files into a simple file that has pairs of values, its quite hard to explain, i think it will be easier if you just look at the file;

PROCEDURE VALIDA_CAMBIO_GPR
TRUNCATE TMP_MOD_PVA
INSERT TMP_MOD_PVA
PROCEDURE AJUSTAR_FECHAS
INSERT PRO_TDA_VARLOG_ALM
PROCEDURE DEPURAR_CAMBIOS_GPR
PROCEDURE INC_EX_0001
INSERT CABECERA_ALARMAS
PROCEDURE INC_EX_0002
INSERT CABECERA_ALARMAS
PROCEDURE INC_EX_0003
INSERT CABECERA_ALARMAS
PROCEDURE INC_EX_0005
INSERT CABECERA_ALARMAS
PROCEDURE INC_EX_0007
INSERT CABECERA_ALARMAS
PROCEDURE INC_EX_0008
INSERT CABECERA_ALARMAS
PROCEDURE INC_EX_0009
INSERT CABECERA_ALARMAS
PROCEDURE INC_EX_0010
INSERT CABECERA_ALARMAS
PROCEDURE INC_EX_0011
INSERT CABECERA_ALARMAS

好吧,这个文件持续4000行,但是我不需要所有的行,我想要的只是同一张表的TRUNCATE和INSERTS对,所以例如从上一个文件中我只想保留包含该对和该对的过程的名称.

Ok, this file goes on for 4000 lines, but i dont need all of the lines, all i want are the pairs of TRUNCATE and INSERTS of the same table, so for example out of the last file i would only want to keep the name of the procedure containing the pair, and the pair. f.e

PROCEDURE VALIDA_CAMBIO_GPR
TRUNCATE TMP_MOD_PVA
INSERT TMP_MOD_PVA

如您所见,TRUNCATE和INSERT影响同一张表,每个过程也可能有一对以上.我该怎么办? 我不希望没有这些对的所有过程,而且我也不想任何没有它们对的插入物被截断. 如果解释不好,很抱歉,如果oyu在理解上有困难,请发表评论,我会尽力进行升级.

As you can see, the TRUNCATE and INSERT affect the same table, there may also be more than one pair per procedure. How could i do this? I DO NOT WANT all the procedure's that dont have these pairs, and i also don't want any truncates of inserts that don't have their pair. Sorry for the bad explanation, if oyu have problems understanding just comment and i'll do my best to upgrade.

PD:我正在使用ksh.

PD: Im using ksh.

推荐答案

使用awk:

awk '$1=="PROCEDURE"{p=$0;next} p && $1=="TRUNCATE"{t=$2;next} t==$2 && $1=="INSERT"{
     print p; print "TRUNCATE" t; print "INSERT" t; print ""; t=""}' file
PROCEDURE VALIDA_CAMBIO_GPR
TRUNCATETMP_MOD_PVA
INSERTTMP_MOD_PVA

这篇关于如何删除除包含TRUNCATE-INSERT的行以外的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆