LC_ALL=C fgrep -f /root/inputfile.txt *.txt > outputfile.txt

inputfile contains this kind of stuff;


*.txt (multiple files) contains things such as


When I grep a small list of names from the input file, some which exist in the *.txt's, some which don't. I get other false results.

000_na_name_000:493982:[email protected]:2000-01-05:XX:X:123.123:alias

There is absolutely nothing in the input that should case these false results, and there's a lot of them.

  • It seems that when i use only one input word in a file, it finds results for the one word only with no mis-matches. When I have more it does not seem to do the same, but I cannot seem to find the trigger.
    – don joe
    Commented Aug 21, 2014 at 4:52
  • 1
    can you give one real scenario example for inputfile.txt and for 1.txt and 2.txt or so. And also with these 3 files, what is the needed outputfile.txt.
    – Jayesh
    Commented Aug 21, 2014 at 5:00
  • pastebin.com/5TnGJx3J - pastebin.com/gD2s7sPQ / something in these inputs has caused the problem whilst..
    – don joe
    Commented Aug 21, 2014 at 5:18
  • pastebin.com/0cZUpCGu does not cause the same problem
    – don joe
    Commented Aug 21, 2014 at 5:19
  • 1
    Does inputfile.txt contain an empty line by any chance? Commented Aug 21, 2014 at 19:02

1 Answer 1


From the example in the question, it looks like it should really work, regarding the usage of fgrep.

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 *.txt files.
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .