Print only some strings from an output

Hi,

Here is an example:

I have a grep line:

grep -i -r -H "$WORD" "$DIRECTORY"

with an output like this:

/media/dir/dir2//dir4/file.txt:/media/dir/dir2/dir3/file_16072008/es6.txt: "content of the file found from grep"/media/dir/dir2/dir3/dir4/file3.txt:/media/dir/dir2/dir3//file.txt:"other found content"

I want to get this output from grep and print only the found content with the file in which it was found, in this example I want to print (with newline between every file):

/media/dir/dir2/dir3/dir4/file_16072008/es6.txt: "content of the file found from grep"
/media/dir/dir2/dir3/dir4/file.txt:"other found content"

Is that possible?

Thanks

Can you please elaborate your requirement clearly.

your command works fine.

hitendra@nabla:~$ grep -i -r -H match dir
dir/file1:this is 1st match
dir/file1:this is 2nd match
dir/file2:this is another match
dir/file3:matchhh
dir/file3:this is yet another match
hitendra@nabla:~$ grep -i -r -H -w match dir
dir/file1:this is 1st match
dir/file1:this is 2nd match
dir/file2:this is another match
dir/file3:this is yet another match
hitendra@nabla:~$

I'm sorry you are right, I made some changes in my script, I actually need to use the output of a "find" for example:

find "$DIRECTORY" -type f

prints:

/dir1/dir2/file1
/dir1/dir2/file2
/dir1/dir2/file3
/dir1/dir2/file4

and use EACH LINE as input for a grep, because I want to use grep to search content in each file inside the output of my "find" command.

thanks

Try

find "$DIRECTORY" -type f -exec grep -iH $WORD {} +