What you are posting should work. The fact that it doesn't means there is something specific in your files, we can't help you if you don't give us real examples that don't work. At least show us the real output of your for loop. What does the echo echo? Can you give us a minimal working (failing) example?
–
terdon♦Jul 18 '13 at 15:04

Even if the string would be incomplete (which it isn't because it prints 4 spaces before, so cut is ok), it should find that string. As said in the question - the names are outputed correctly, but it's afterwards that it won't find anything. Could there be a newline character at the end that messes it up?
–
user857990Jul 17 '13 at 12:03

@user857990 - I'd need to see the fortigate.conf file to confirm, but if you're OK with how the first grep works, then that would seem to be the next logical place to look. The outer for ... grep ... seems to be "working" otherwise.
–
slm♦Jul 17 '13 at 12:09