What shell are you using?
I'm a bit confused with what it is trying to do, but here goes:-
for i in $(find /file directory/ -type d | grep file name)
do
prefix=`echo $i | cut -f5 -d"/"`
out=$prefix.out
echo $prefix
for i in starts a loop between the following do & done (which you haven't got, so it will fail with a syntax error, unless this is just a snippit.
The $( through to ) set up the conditions for the loop by executing the contents.
It then gets a bit murky. I'm hoping that the "file directory" and "file name" are actually single items, not with spaces in them, else the meaning changes completely. If they are actually filedirectory and filename then the find command will search from filedirectory for any other directories because of the option -type d
You loop then executes for each occurrence.
The prefix= is an odd statement, but it is getting the 5th field of the directory name found. So if you had the following, you would get this output:-
/filedirectory/a/b no output
/filedirectory/a/b/c c
/filedirectory/a/b/c/d c
The first field here is before the first / so that's why c is the only thing displayed on the second line. Because you are after the 5th field, you never get the d from the third line. If you do want that level and all subsequent, change the cut to be cut -f5- -d "/"
You then assign variable out to be the value determined above appended with .out and then never use it, just displaying the line determined above.
So, if you have the directory structure alluded to above, you would get the final output of this:-
blank line
c
c
What are you trying to achieve overall? There is probably a better (less processing/IO) and neater way to do it.
I hope that this helps.
Robin
Liverpool/Blackburn
UK