grep not returning text known to be in file (opens in new tab)
Symptom cat displays text, but grep can't find it: % cat foo.txt The world is overcome--aye! even here! By such as fix their faith on Unity. % grep fix foo.txt % Cause The file is UTF-16, not UTF-8/ASCII. For example, in UTF-16LE, fix is encoded as: 66 00 69 00 78 00 not as the contiguous ASCII bytes, which are also the UTF-8 bytes for fix: 66 69 78 So grep fix does not match. cat output may appear normal since NUL bytes are often not visibly rendered. Detect encoding % file foo.txt foo.txt: ...
Read the original article