Make beagrep-files more robust

Signed-off-by: Bao Haojun <baohaojun@gmail.com>