[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How do I pad files in Linux?



On 6/29/2013 12:19 PM, Tixy wrote:
> On Sat, 2013-06-29 at 12:34 -0400, 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? 
> 
> 
> truncate -s %80 FILENAME
> 
> Will pad with zero's to round size up to a multiple of 80.

That'll teach me to read all posts before replying.  Question:

Does this append ASCII zeros to the end of the file, or nulls?  Stephen
asked for nulls, and you state "zero's" above.

-- 
Stan



Reply to: