Article 58XSG sed stop insert the line after the first occurrence of the pattern

sed stop insert the line after the first occurrence of the pattern

by
mackowiakp
from LinuxQuestions.org on (#58XSG)
Lets take such text file named "/tmp/test":

Code:yyyy-1
xxxx-2
xxxx-3
zzzz-4
xxxx-5I want to insert additional line containing "aaaa-6" before first occurrence of line containing string "xxxx" at the beginning of line. But only one time, as I wrote at first occurrence.

For this purpose I want to use the script like this:

Code:#!/bin/sh

entry="aaaa-6"
sed -i "/^xxxx*/a $entry" /tmp/testBut this script insert after each occurrence of pattern.
Any idea how to stop sed after first occurrence?
Notice that /bin/sh is used (busybox) not bash.latest?d=yIl2AUoC8zA latest?i=Y1702GCkEno:JRAFqOIs41c:F7zBnMy latest?i=Y1702GCkEno:JRAFqOIs41c:V_sGLiP latest?d=qj6IDK7rITs latest?i=Y1702GCkEno:JRAFqOIs41c:gIN9vFwY1702GCkEno
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments