The format of the `magic` file is described in the `magic(5)` manual on your system (`man 5 magic`).
On an Ubuntu system I have access to (as well as on my OpenBSD system), the format is described as a collection of lines with the following fields:
offset type test message
I'm guessing that your file should therefore not contain four lines, but one:
42 search 42 Itis42file
This does indeed work on OpenBSD:
$ cat ~/.magic
42 search 42 Itis42file
$ cat file.txt
42 hello
$ file file.txt
file.txt: Itis42file