Try this.
Code:
sed '0,/nameserver/ { /nameserver/i nameserver 208.67.122.221
}' file
First, match from start-of-file to nameserver, then match again inside that selection. Unfortunately though, the a,i,c commands terminate on newlines, so you have to physically break the line in order to finish up the expression.
Your shell allows a bit of a trick though that will allow you to do it on one line:
Code:
sed $'0,/nameserver/ { /nameserver/i nameserver 208.67.122.221 \n }' file
$'..' is an extended quoting system that expands backslashed characters like
\n, similar to
echo -e.
Edit: Here's another way to do it that doesn't require as much thinking:
Code:
sed -r "0,/nameserver/ s/(.*nameserver.*)/nameserver 208.67.122.221\n\1/" file