log rotation

Hello all.

Due to some reason I can not use HUP to rotate needed log files.
So I use the standard method:
cp $file $file.1
cat /dev/null > $file

But if Java application in this time writing the output to $file,
in the beginning of it appears many "^@^@^@^@^@^@".

How to avoid it? Or how to remove these symbols, maybe sed?
Or maybe someone knows how to clean $file in the better way.

Thanks.

perl -i -ne 's/\^@//g; print;' filename

It erases all file.

Ooops..Its not normal characters ...
Chk this:
To get this non printable character, use Ctrl-V- Ctrl-@

sed 's/^V^@//g'  filename > new_file

It sounds to me like the application in question does not support log rotation of this type; i.e. it is writing its output to a specific location in the file, so even if you 'flatten' the file by copying /dev/null over it, it will still write to that same offset, filling the beginning of the file with nulls (what you are seeing as ^@).

You will probably need to restart this application each time you want to rotate its logs.

Yeah, but I can not restart ir each time I need to rotate log files.
All I need it's move '^@' from 'nulled' log.

I think that I need to try not cat /dev/null > $file, maybe something like sed -e '/^.*$/d'

I think it may be unnecessary to remove the nulls. I presume you are rotating the logs to save space? You may find that the file has now become a 'sparse' file. If you run a du -k logfile does the size reported match the same size as in ls -l logfile? If the du size is much smaller then it is a sparse file and not using much space, so you may as well leave it as it is.