I have 2 suggestions to help you debug.
1. Use the full path for the system commands. I.e. gzgrep and grep.
2. Start small. Cut your command down to just
Then once you verify that command works (if it doesn't, I would suggest you have a fundamental problem which needs addressing), add on to it until you find a spot that doesn't work. Then you know what the problem is more likely to be.