title: Match only very first occurrence of a pettern using awk
body: <p>I am trying to follow the solution at</p>
  
  <p><a href="https://stackoverflow.com/questions/55147798/moving-matching-lines-in-a-text-file-using-sed">Moving matching lines in a text file using sed</a></p>
  
  <p>The situation is that pattern2 needs to be applied just once in the whole file. How can I change the following to get this done</p>
  
  <pre><code>awk '/pattern1/ {t[1]=$0;next}
       /pattern2/ {t[2]=$0;next}
       /pattern3/ {t[3]=$0;next}
       /target3/ { print t[3] }
       1
       /target1/ { print t[1] }
       /target2/ { print t[2] }' file
  </code></pre>
  
  <p>Here is the file on which I applied the pattern2 (RELOC_DIR)</p>
  
  <pre><code>asdasd0
  -SRC_OUT_DIR = /a/b/c/d/e/f/g/h
  RELOC_DIR = /i/j/k/l/m
  asdasd3
  asdasd4
  DEFAULTS {
  asdasd6
  $(RELOC_DIR)/some other text1
  $(RELOC_DIR)/some other text2
  $(RELOC_DIR)/some other text3
  $(RELOC_DIR)/some other text4
  </code></pre>
  
  <p>and the last 4 lines of the file got deleted because of the match.</p>
  
  <pre><code>asdasd0
  -SRC_OUT_DIR = /a/b/c/d/e/f/g/h
  asdasd3
  asdasd4
  DEFAULTS {
  RELOC_DIR = /i/j/k/l/m
  asdasd6
  </code></pre>