Print text between 2 identical strings

hey,
i m having a hard time trying to print only the first occurrence between 2 idenicale strings.

for the following output:

please
help
me im a 
noob
please
im a noob
help me
noob
please
help
me im a 
noob
please
im a noob
help me
noob

i m trying to get only the first occurrence between "noob" and "noob" like so:

noob
please
im a noob

thats what i got so far:

sed -e '1,/noob/d' -e '/noob/,$d' file.txt

but it returns only:

please
im a

but i want it to also print the "noob" string.

any help will be great
Thanks!!!

Hello boaz733,

Could you please try following and let me know if this helps you.

awk '/noob/{A++;if(A==1 || A==2){print};next};{if(A==1){print}}'  Input_file

Output will be as follows.

noob
please
im a noob
 

Thanks,
R. Singh

1 Like

it's perfect - thanks!

Try

sed -n '/noob/{:L;N; /noob.*noob/bK; bL; :K;p;q}' file
noob
please
im a noob

---------- Post updated at 15:04 ---------- Previous update was at 14:58 ----------

awk:

awk '/noob/ {print; if (L) exit; L=1; next} L'  file2
noob
please
im a noob
2 Likes