How can I append lines after a pattern match in awk based on how many lines they are after the pattern match.What I have looks like this:StuffPATTERNa b ca b ca b cENDOFSECTIONMorestuffI would like to add various things to the of end of the lines shown as a b c (without knowing what a b c are specifically i.e., they are arbitrary).Desired output:StuffPATTERNa b c   ka b c   ka b c   tENDOFSECTIONMorestuffI think this will require some sort of loop that counts lines after the pattern is recognised. My issue is I don't know how to link the counting of lines to variable after a pattern search. My very rough idea so far (which doesn't work):awk '/PATTERN/ {i=1Do{print $0,    ki++} while (i<=2)}
Append based on line count in awk after pattern match
text processing;awk
awk '  BEGIN {split(ABCDEFGH, new, )}  /ENDOFSECTION/ {addcol=0}  addcol {$(++NF) = new[++i]}  /PATTERN/ {addcol=1; i=0}  {print}' fileStuffPATTERNa b c Aa b c Ba b c CENDOFSECTIONMorestuffThe BEGIN block is an example of how to create an array of new stuff to add.Then, the awk program acts like a state machine, setting/unsetting a flag when certain patterns are seen.