can I do this with dd ?

can I do this with dd ?

Post by Lucio Chiappet » Thu, 30 Mar 1995 04:00:00



Assume I want to do the following :

  - I have a binary file with many records of size 1106 bytes
  - I want to convert it in a file with the same records, but each one
    shall be padded to a record size of 1108 bytes
    (the data used for the padding do not matter)

is there some obscure combination of dd switches that allow me to do it ?

I haven't found one in practice but the following cumbersome way

   extract first record with
   dd if=btb00999.p1psa000 of=temp1 bs=1106 count=1

   extract second record with
   dd if=btb00999.p1psa000 of=temp2 bs=1106 skip=1 count=1

   extract third record with
   dd if=btb00999.p1psa000 of=temp3 bs=1106 skip=2 count=1

   etc.

create a file containing two bytes (e.g. cat >twobyte, cr, cr, ctld-D)

recompose the file with

   cat temp1 twobyte temp2 twobyte temp3 twobyte ... >outputfile

----------------------------------------------------------------------------
       A member of  G.ASS : Group for Astronomical Software Support          
----------------------------------------------------------------------------
Lucio Chiappetti - IFCTR/CNR     | Ma te' vugl' da' quost avis a ti' Orsign  
via Bassini 15 - I-20133 Milano  | Buttet rabios intant te se' pisnign      

Decnet:   IFCTR::LUCIO           |             (Rabisch, II 46, 119-120)    
----------------------------------------------------------------------------

 
 
 

can I do this with dd ?

Post by Tye McQue » Thu, 06 Apr 1995 04:00:00


)   - I have a binary file with many records of size 1106 bytes
)   - I want to convert it in a file with the same records, but each one
)     shall be padded to a record size of 1108 bytes
)     (the data used for the padding do not matter)
)
) is there some obscure combination of dd switches that allow me to do it ?

This comes close:

    dd ibs=1106 cbs=1106 obs=1107 conv=unblock |
     dd ibs=1107 cbs=1108 obs=1108 conv=block

The only problem is if you have newlines in your input file.

The first line reads 1106 bytes at a time (ibs=1106), puts them
in a 1106-byte buffer (cbs=1106), pads them (won't happen unless
you have a newline in the block which will cause only stuff up-to
the newline to be loaded and the subsequent data to be put in a
separate block), then appends a newline and outputs the resulting
1107-byte (obs=1107) block.

The second line reads each of these 1107-byte blocks, stips the
newline and puts them in a 1108-byte buffer (cbs=1108), pads them
with (two) spaces, then outputs the resulting 1108-byte blocks
(obs=1108).

If there is some character that you know never appears in your
data, you can use it to handle newlines:

    tr '\012' '\377' |
     dd ibs=1106 cbs=1106 obs=1107 conv=unblock |
     dd ibs=1107 cbs=1108 obs=1108 conv=block |
     tr '\377' '\012'

My "toy" version of "tr" (UnixWare 1.1) doesn't handle NUL
bytes so I can't use '\000' as God intended.
---

             Nothing is obvious unless you are overlooking something

 
 
 

can I do this with dd ?

Post by Jim Nakamu » Sun, 16 Apr 1995 04:00:00



| )   - I have a binary file with many records of size 1106 bytes
| )   - I want to convert it in a file with the same records, but each one
| )     shall be padded to a record size of 1108 bytes
| )     (the data used for the padding do not matter)
| )
| ) is there some obscure combination of dd switches that allow me to do it ?

| This comes close:

|     dd ibs=1106 cbs=1106 obs=1107 conv=unblock |
|      dd ibs=1107 cbs=1108 obs=1108 conv=block

| The only problem is if you have newlines in your input file.

| The first line reads 1106 bytes at a time (ibs=1106), puts them
| in a 1106-byte buffer (cbs=1106), pads them (won't happen unless
| you have a newline in the block which will cause only stuff up-to
| the newline to be loaded and the subsequent data to be put in a
| separate block), then appends a newline and outputs the resulting
| 1107-byte (obs=1107) block.

        I'm confused.  I thought unblock meant trailing
        blanks are removed so the first line would take
        1106 bytes of a blocked file and remove trailing
        blanks and then add a newline before writing
        it out.  I didn't think newlines in a blocked
        file had any effect.  If a newline was in
        position 60 of a blocked file, wouldn't 1106
        bytes still be read?

| The second line reads each of these 1107-byte blocks, stips the
| newline and puts them in a 1108-byte buffer (cbs=1108), pads them
| with (two) spaces, then outputs the resulting 1108-byte blocks
| (obs=1108).

| If there is some character that you know never appears in your
| data, you can use it to handle newlines:

|     tr '\012' '\377' |
|      dd ibs=1106 cbs=1106 obs=1107 conv=unblock |
|      dd ibs=1107 cbs=1108 obs=1108 conv=block |
|      tr '\377' '\012'

| My "toy" version of "tr" (UnixWare 1.1) doesn't handle NUL
| bytes so I can't use '\000' as God intended.

--

 
 
 

1. dd of DOS MBR wanted (to boot dos on hdb)

Can someone email me a copy of their DOS MBR? Mine has evidently
gotten erased from hdb during my fiddling. fdisk /mbr like to do
its work on hda and I do not want to have to rejumper my disks just
to install an MBR.

As a further explanation, I want to do this so that I can boot DOS
on hdb1. It does not seem to work if I just point lilo (or the minix
monitor on hdb2) to hdb1. I noticed that to boot redhat on hda1, the
minix boot monitor requires I point it to hd0, which is equivalent
to just hda in lilo. (Lilo of course seems ok with hda1.) It got me
thinking that maybe I should point monitor (or lilo) to hd5 (hdb).

Right now, if I point lilo to hdb1 or minix monitor to hdb6 (=hdb1),
I get "invalid system disk". Inserting a dos boot floppy works ok
and I can switch to the C: filesystem just fine. I want to do this
front the bootloaders however.

Sent via Deja.com http://www.deja.com/
Before you buy.

2. ? what happened to LinuxPPC.org ?

3. Using the dos version of dd...

4. Is my Linux Corrupted??

5. Using dd copy image file to make a DOS bootable disk

6. solaris 9 and ldap???

7. Changing all date fields from mm/dd/yy to dd/mm/yy

8. New comer into this perfect World of Linux

9. dd | remsh dd under AIX 1.2

10. dd command: extract single files out of a dd-file

11. Need DOS port of UNIX "dd" command.

12. To dd or not to dd that is the question!

13. dd utility for dos