Re: How do I pad files in Linux?
On 6/29/2013 11:34 AM, Stephen Powell wrote:
> I have a need to pad a binary file with some character
> (probably a null character) so that its total length
> is a multiple of some number. For example, I have a file
> called kernel.debian, whose size is 6319616 bytes. I need
> to pad it with nulls until its length is a multiple of 80.
> The next higher multiple of 80 is 6319680, which can be
> obtained by padding the file with 64 null characters.
> In CMS, the FBLOCK CMS Pipelines stage will do the trick.
> For example,
>
> PIPE < KERNEL DEBIAN A1 | FBLOCK 80 00 | > KERNEL1 DEBIAN A1 F
>
> This will create an output file with fixed-length 80-byte
> records, padded as necessary at the end with null characters,
> so that all records are exactly 80 bytes long.
>
> I am looking for a way to do this padding in Linux.
> A search of the internet using the keywords "pad file Linux"
> did not seem to produce any useful results. Does anyone know
> how to accomplish this?
One possibility might be
~$ cat file1 file2 >> file3
where file1 is your binary and file2 contains 64 nulls. Now you simply
need to create a file containing exactly 64 nulls. I've never screwed
with this, but I'd guess it can be done with one of the scripting
languages, maybe a text manipulator such as awk or its variants, etc.
Loop a print command with the proper special character syntax for null
64 times piping the output to file2. You may even be able to create it
in vi.
--
Stan
Reply to: