Find pattern a delete previous 5 lines

Hi guys,

i have the follow problem i need to delete 10 row before the pattern and 1 after and the pattern row itself.

file looks like:

frect 9.8438 25.8681 10.625 25 
        . dynprop  \
              (#  \
                (call fox_execute(__self)))  \
              (FOX_VAR_29  \
                (= *   \
                  (fcolor FOX_VAR_29)))  \
              (o23  \
                (= *   \
                  (call fox_oos(__self))))
        . userdata "FOX_VAR=29^attr=FCOLOR^attrval=6^required=0^var=V_0001:00TZ_1005.ALMSTA^delta=1.000000^conv=BITMASK^type=LONG^num_entries=15^entries=0X440000E0,0X44000020,ALL,25,0X420000E0,0X42000020,ALL,25,0X410000E0,0X41000020,ALL,25,0X404000E0,0X40400020,ALL,25,0X402000E0,0X40200020,ALL,25,0X401000E0,0X40100020,ALL,25,0X400200E0,0X40020020,ALL,25,0X400100E0,0X40010020,ALL,25,0X400000E0,0X40000000,ALL,63,0X440000E0,0X4000020,ALL,17,0X420000E0,0X2000020,ALL,17,0X410000E0,0X1000020,ALL,17,0X400200E0,0X20020,ALL,17,0X400100E0,0X10020,ALL,17,0,0,ALL,24^END_FOXV=  ^aname=NULL^alevel=0^action=EXECUTE^required=0^cmd== P4 V_0001 ; = P5 00TZ_1005 ; = P6 1 ; script /opt/script/MTF/ovlCIN^oos_obj=0023"
        . userword 130
        frect 10.625 25.8681 11.4062 25 
        . dynprop  \
              (#  \
                (call fox_execute(__self)))  \
              (FOX_VAR_30  \
                (= *   \
                  (fcolor FOX_VAR_30)))  \
              (o24  \
                (= *   \
                  (call fox_oos(__self))))
        . userdata "FOX_VAR=30^attr=FCOLOR^attrval=6^required=0^var=V_0001:00TZ_1009.ALMSTA^delta=1.000000^conv=BITMASK^type=LONG^num_entries=15^entries=0X440000E0,0X44000020,ALL,25,0X420000E0,0X42000020,ALL,25,0X410000E0,0X41000020,ALL,25,0X404000E0,0X40400020,ALL,25,0X402000E0,0X40200020,ALL,25,0X401000E0,0X40100020,ALL,25,0X400200E0,0X40020020,ALL,25,0X400100E0,0X40010020,ALL,25,0X400000E0,0X40000000,ALL,63,0X440000E0,0X4000020,ALL,17,0X420000E0,0X2000020,ALL,17,0X410000E0,0X1000020,ALL,17,0X400200E0,0X20020,ALL,17,0X400100E0,0X10020,ALL,17,0,0,ALL,24^END_FOXV=  ^aname=NULL^alevel=0^action=EXECUTE^required=0^cmd== P4 V_0001 ; = P5 00TZ_1009 ; = P6 1 ; script /opt/script/MTF/ovlCIN^oos_obj=0024"
        . userword 130

I then need to search on a tag number this is V_0001:00TZ_1005 and delete the 11 rows. can you help me ?

Try something like this:

awk 'NR==FNR{if($0 ~ "V_0001:00TZ_1005"){n=NR}next} FNR < n-9 || FNR-n > 1' file file
1 Like

tried it doesn't do anything

source file is called V_0001.g

awk 'NR==FNR{if($0 ~ "V_0001:00TZ_1005"){n=NR}next} FNR < n-9 || FNR-n > 1' V_0001.g

i have tried it but no score :slight_smile:

Use input file 2 times as given by Franklin

awk 'NR==FNR{if($0 ~ "V_0001:00TZ_1005"){n=NR}next} FNR < n-9 || FNR-n > 1' file file
1 Like

that did the trick ! thanks guys great work