Sed searches a range and prints the first set

advertisements

I have a file like as follows

myname
_       something
_       something
_       something
myname
_       something
_       something
myname
_       something
and it follows and no standard other than myname word.

Now I want to print the first set of search from myname to till myname found as below.

myname
_       something
_       something
_

I tried using the following but it is not working.

sed -n -e '/myname/,/myname/ p' file

It prints all the sets.

Tried this also but not worked.

sed -n '/myname/,$ p;/myname/q'


awk  '/myname/{if(b) exit; else b=1}1' filename

$ cat temp.txt
myname
_       something
_       something
_       something
myname
_       something
_       something
myname
_       something

$ awk  '/myname/{if(b) exit; else b=1}1' temp.txt
myname
_       something
_       something
_       something