regex - Awk/sed solution for replacing/prepending subset of lines in between 2 patterns -


i use sed/awk edit/prepend specific lines in between 2 patterns (east_40_1_ep00 &arr , #pchan 5). here block of text:

   east_40_1_ep00 &arr{            # template 6-channel units @ brtt                              #       nothing specified means use global parameters             pchan_map &arr{         #these map q330 physical channels seed net-sta-chan-loc codes             #       pchan   net_sta_chan[_loc]      calib   calper  segtype                       0       $dlnet_$dlsta_bhz_00    $db                      1       $dlnet_$dlsta_bhn_00    $db                      2       $dlnet_$dlsta_bhe_00    $db                      0       $dlnet_$dlsta_lhz_00    $db                      1       $dlnet_$dlsta_lhn_00    $db                      2       $dlnet_$dlsta_lhe_00    $db                      3       $dlnet_$dlsta_bhz_01    $db                      4       $dlnet_$dlsta_bhn_01    $db                      5       $dlnet_$dlsta_bhe_01    $db                      3       $dlnet_$dlsta_lhz_01    $db                      4       $dlnet_$dlsta_lhn_01    $db                      5       $dlnet_$dlsta_lhe_01    $db             }             acq_matrix &tbl{                                # acquisition matrix             #       str0 str1 str2 str3 str4 str5 str6 str7              #       1    10   20   40   50   100  200                       m1   0    0    m40  0    0    0    0  # pchan 0                     m1   0    0    m40  0    0    0    0  # pchan 1                     m1   0    0    m40  0    0    0    0  # pchan 2                     m1   0    0    m40  0    0    0    0  # pchan 3                     m1   0    0    m40  0    0    0    0  # pchan 4                     m1   0    0    m40  0    0    0    0  # pchan 5             }     } 

i add comment tags "#' lines 11-16, , 24,26 using sed/awk, block of text looks like:

  east_40_1_ep00 &arr{            # template 6-channel units @ brtt                              #       nothing specified means use global parameters             pchan_map &arr{         #these map q330 physical channels seed net-sta-chan-loc codes             #       pchan   net_sta_chan[_loc]      calib   calper  segtype                       0       $dlnet_$dlsta_bhz_00    $db                      1       $dlnet_$dlsta_bhn_00    $db                      2       $dlnet_$dlsta_bhe_00    $db                      0       $dlnet_$dlsta_lhz_00    $db                      1       $dlnet_$dlsta_lhn_00    $db                      2       $dlnet_$dlsta_lhe_00    $db             #         3       $dlnet_$dlsta_bhz_01    $db             #         4       $dlnet_$dlsta_bhn_01    $db             #         5       $dlnet_$dlsta_bhe_01    $db             #         3       $dlnet_$dlsta_lhz_01    $db             #         4       $dlnet_$dlsta_lhn_01    $db             #         5       $dlnet_$dlsta_lhe_01    $db             }             acq_matrix &tbl{                                # acquisition matrix             #       str0 str1 str2 str3 str4 str5 str6 str7              #       1    10   20   40   50   100  200                       m1   0    0    m40  0    0    0    0  # pchan 0                     m1   0    0    m40  0    0    0    0  # pchan 1                     m1   0    0    m40  0    0    0    0  # pchan 2             #        m1   0    0    m40  0    0    0    0  # pchan 3             #        m1   0    0    m40  0    0    0    0  # pchan 4             #        m1   0    0    m40  0    0    0    0  # pchan 5             }     } 

i don't mind executing 2 separate commands if have to, 1 ideal. have 2 commands grab out subset lines, unsure how can modify them make edit actual file lines:

  sed -n "/east_40_1_ep00 &arr/,/#pchan 5/p" q3302orb_test.pf | sed -n '11,16p' | awk '{print "#"$0 }' file    sed -n "/east_40_1_ep00 &arr/,/#pchan 5/p" q3302orb_test.pf | sed -n '24,26p' | awk '{print "#"$0 }' file 

can me out how 1) combine these commands 1 command, , 2) edit file not print out lines. i've tried using -i command in various places no luck.

thanks in advance!

#!/usr/bin/awk -f begin {   alpha[11] alpha[12] alpha[13] alpha[14] alpha[15] alpha[16]   alpha[24] alpha[26] } /east_40_1_ep00 &arr/ {   bravo = 1   charlie = nr } /#pchan 5/ {   bravo = 0 } bravo && nr-charlie+1 in alpha {   $0 = "#" $0 } 1 
  1. set array of lines
  2. once start marker found, save it
  3. also save line number of start marker
  4. set stop marker
  5. between markers, if line number good, add comment
  6. print

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -