I have about 500 files with trailing NUL bytes, maybe produced with
truncate -s 8M <file>
How can I cut off the zeroes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This perl script should do it:
This will keep all NULs within the file, remove any at the end, and save the result into
<original filename>_fixed.Script explanation:
$/=undeftells perl to operate on the whole file rather than splitting it into lines;$_=<>loads the file;s|\0+||removes any string of NULs at the end of the loaded file ‘string’; andprintoutputs the result. The rest is standard Bash file redirection.