I have a 300 lines file with
^@ character between each characters in the file.
(I cannot post the entire contents for security reasons, so I am pasting only the first line)
[mercury@app01 ftp_logs]$ cat cl.txt 2015-01-22 03:00:01; local;
Now, when I
vi the file, I see the same contents as following:
2^@0^@1^@5^@-^@0^@1^@-^@2^@2^@ ^@0^@3^@:^@0^@0^@:^@0^@1^@;^@ ^@l^@o^@c^@a^@l^@;^@
cat wasn't displaying the
^@ characters, naturally I thought grepping for a certain string would work in
cat, but surprisingly, it wasn't.
[mercury@app01 ftp_logs]$ cat cl.txt 2015-01-22 03:00:01; local; [mercury@app01 ftp_logs]$ cat cl.txt | grep local [mercury@app01 ftp_logs]$
After replacing the null bytes with
sed, file is now readable in
grep returns the result from
[mercury@app01 ftp_logs]$ sed -i 's/\x0//g' cl.txt [mercury@app01 ftp_logs]$ cat cl.txt | grep local 2015-01-22 03:00:01; local; [mercury@app01 ftp_logs]
1) Why didn't
grep work before replacing the null bytes, given that null bytes weren't getting displayed. Does it mean
grep saw the
^@ characters even though it wasn't displayed in the terminal?
2) This makes me wonder whether it is recommended to use
cat -v or
vi to read files on production servers since
catseem to be good in hiding stuff?
3) The file in question is an auto-generated file from a Windows machine. Under what circumstances does the
^@ find its way into a file.