title: How to delete all the lines after the last occurence of pattern?
body: <p>i want to delete all the lines after the last occurence of pattern except the pattern itself</p>
  
  <p>file.txt</p>
  
  <pre><code>honor
  apple
  redmi
  nokia
  apple
  samsung
  lg
  htc
  </code></pre>
  
  <p>file.txt what i want </p>
  
  <pre><code>honor
  apple
  redmi
  nokia
  apple
  </code></pre>
  
  <p>what i have tried </p>
  
  <pre><code>sed -i '/apple/q' file.txt
  </code></pre>
  
  <p>this deletes all the line after the first occurence of pattern -</p>
  
  <pre><code>honor
  </code></pre>