Serach a string for multiple occurrences in a file and cut related texts

Hi,

I want a help in this forum for my below issue.

  1. I have a file where I'm searching for a text .
  2. When I get the line where the above string is present I want to cut
    some texts from the line where the particular string was found.

These above two steps will repeat in the file for multiple times.

eg.
-------------------------------------------------
file1

aaabhaskisss hi wassup dere
sssssssssssssssssssssssssssssssssssss

cccbhaskiddd hi wat u gotta
gggggggggggggggggggggggggg

-------------------------------------------------

In the above file

  1. I want search all the occurrences of the text bhaski(above we have two occurrences)
  2. when bhaski string is found in a line I want the all texts which is 5 charecters after from the string bhaski

So the final o/p would be as below
-------------------------------------
hi wassup dere
hi wat u gotta
-------------------------------------

Can you please help me in this.
Thanks in advance.

sed -n 's/.*bhaski.\{4\}\(.*\)/\1/p'  file

Guru

sed -n 's/.*bhaski....\(.*\)/\1/p' file

PLEASE USE CODE TAGS

Ah, Guru Again!!! :slight_smile: