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.


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.