shell - How to delete all lines except lines that include TRUNCATE - INSERT, incluiding PACK name -



shell - How to delete all lines except lines that include TRUNCATE - INSERT, incluiding PACK name -

this extension question: how delete lines except lines include truncate - insert

i had before asked question because needed help deleting line generated script, thanx great help anubhava able solve problem, proble have been asked include pack name generated script, so:

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

this original problem had long text file lines that, wanted delete lines did not have couple of insert-truncate per procedure, result previous line

procedure valida_cambio_gpr truncate tmp_mod_pva insert tmp_mod_pva

to used 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=""}'

ok, here have no problem, now, when have been told include pack name obove procedure, text file looks this.

pack packenvi procedure valida_cambio_gpr truncate tmp_mod_pva insert tmp_mod_pva packansi procedure calcula_gramos pack packbrum procedure ajustar_fechas insert pro_tda_varlog_alm pack packrensi procedure depurar_cambios_gpr pack packrensi procedure inc_ex_0001 insert cabecera_alarmas pack packrensi procedure inc_ex_0002 insert cabecera_alarmas pack packrensi procedure inc_ex_0003 insert cabecera_alarmas pack packrensi procedure inc_ex_0005 insert cabecera_alarmas pack packrensi procedure inc_ex_0007 insert cabecera_alarmas pack packrensi procedure inc_ex_0008 insert cabecera_alarmas pack packrensi procedure inc_ex_0009 insert cabecera_alarmas pack packrensi procedure inc_ex_0010 insert cabecera_alarmas pack packrensi procedure inc_ex_0011 insert cabecera_alarmas

the desired output text be:

pack packenvi procedure valida_cambio_gpr truncate tmp_mod_pva insert tmp_mod_pva

it pretty much same problem before, there line needs printed when couple of insert-truncate found below procedure below pack, if procedure more 1 couple of insert_truncate, pairs must printed.

thanks lot, if had problem understanding take @ original question.

awk solution

awk '/pack/{p=$0}/procedure/{p=$0}/truncate/{t=$0}t~$2&&/insert/{print p rs p rs t rs $0;p=p=t=0}' file pack packenvi procedure valida_cambio_gpr truncate tmp_mod_pva insert tmp_mod_pva

for farther lines need printed add together /line/{?=$0} , add together print part well(where ? variable)

shell awk ksh

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -