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

Re: How do I pad files in Linux? (SOLVED)



On Sat, 29 Jun 2013 13:19:22 -0400 (EDT), 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.

Thank you, Tixy, that's exactly what I wanted to know!
I knew that there must be a way to do this, but I couldn't
figure out how.  By the way, I also tried the command

   apropos pad

But it didn't yield any useful results either.

   truncate

Who would have thought?  That would appear to be the opposite
of what I want to do.  I want to pad, not truncate.  But
truncate can also pad.  How about that!  Thanks again!

-- 
  .''`.     Stephen Powell    
 : :'  :
 `. `'`
   `-


Reply to: