I used the below command but it doesn't work.
grep "^@^@^@" *
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
^@ is not a carat
^ and at-sign
@, it's one character. It's how some programs display the NUL character—ASCII value 0, also known as
\0 in C.
Here I've created a file with a NUL byte in it.† Notice that I use
cat -v to show non-printing characters.
$ cat -v blah hello null^@ hi $ hexdump -C blah 00000000 68 65 6c 6c 6f 0a 6e 75 6c 6c 00 0a 68 69 0a |hello.null..hi.| 0000000f
Grep has trouble finding NULs since they're used to terminate strings in C. Sed, however, can do the job:
$ sed -n '/\x0/p' blah null $ sed -n '/\x0/p' blah | cat -v null^@
† In vi, in insert mode press Ctrl-V, Ctrl-Shift-@ to insert a null byte.
In bash you can add special characters when prefixed with
C-v. So you can, for example
grep 'Ctrl-vCtrl-a' file.txt
The search string should be read as
control key +
character v, followed by
control key +
character a, which searches for ASCII value SOH (01). Unfortunately this doesn't work for the NUL character.
Character ^@ is the NUL char, so I'm afraid that it cannot be grepped directly.
Your best option would be probably to write a simple program that searches for this sequence of bytes.
Alternatively you may try to convert it into some form of hexadecimal dump (
xxd or so) and grep into the output of it. But frankly speaking, it would be tricky to get it right.