From the example in the question, it looks like it should really work, regarding the usage of
What looks wrong is that grep will - if an
outputfile.txt existed before - probably search on it's own output again, depending on buffer sizes and input sizes. If
outputfile.txt did not exist before, it seems like
*.txt will not match it, because it does not exist at the time of matching.
It does not really look like the reason for your problem, but it is worth testing what happens when
outputfile.txt is stored elsewhere.
If it's not that, what could you do?
In the comments, you show an example
inputfile.txt which causes the problem.
I assume the problem is caused by one or more lines in that file - when used with the same
To find which lines are the problem, you can do a binary search for the lines: You remove half of the lines, and try whether it works. If the problem went away, you use the removed lines to continue, otherwise the remaining lines. Now you repeat that until you have only one or a few lines left - at which point you probably can see the cause already.