|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
yuriy_zubarev wrote: > I'm curious if there is a command line tool that would > transform the file by padding each line with spaces so that it's > exactly 50 characters long. I'm surprised that nobody has thought to give the solution in the one command utility that has always been provided to do exactly this. >From memory; not tested: dd if=my/file bs=50 conv=block,noerror,sync =Brian |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2006-08-17, bsh wrote:
> > yuriy_zubarev wrote: >> I'm curious if there is a command line tool that would >> transform the file by padding each line with spaces so that it's >> exactly 50 characters long. > > I'm surprised that nobody has thought to give the solution > in the one command utility that has always been provided > to do exactly this. > >>From memory; not tested: > > dd if=my/file bs=50 conv=block,noerror,sync That's probably because it doesn't do what the OP asked for. -- Chris F.A. Johnson, author <http://cfaj.freeshell.org> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Chris F.A. Johnson wrote: > On 2006-08-17, bsh wrote: > > yuriy_zubarev wrote: > padding each line with spaces so that it's exactly 50 characters long. > > I'm surprised ... dd(1) > probably because it doesn't do what the OP asked for. I'm at the relative disadvantage of not being currently able to test my submission, but as I (re)read the OQ, this should do exactly what the OP asked for. So what do you think it does? =Brian |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 2006-08-17, bsh wrote:
> > Chris F.A. Johnson wrote: >> On 2006-08-17, bsh wrote: >> > yuriy_zubarev wrote: >> padding each line with spaces so that it's exactly 50 characters long. >> > I'm surprised ... dd(1) >> probably because it doesn't do what the OP asked for. > > I'm at the relative disadvantage of not being currently able to test > my submission, but as I (re)read the OQ, this should do exactly > what the OP asked for. > > So what do you think it does? $ printf "%s\n" a b c d e f g > txt $ dd if=txt bs=50 conv=block,noerror,sync | od -c 0+1 records in 1+0 records out 0000000 a \n b \n c \n d \n e \n f \n g \n \0 \0 0000020 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 * 0000060 \0 \0 0000062 -- Chris F.A. Johnson, author <http://cfaj.freeshell.org> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Chris F.A. Johnson wrote: > bsh wrote: > > Chris F.A. Johnson wrote: > > > bsh wrote: > > > > yuriy_zubarev wrote: > $ dd if=txt bs=50 conv=block,noerror,sync | od -c > 0000020 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 Hmmm... What I read in the dd(1) manpage before posting was: sync Pad every input block with NULs to ibs-size; when used with block or unblock, pad with spaces rather than NULs. Maybe a variant or GNU extension? Once upon a time, using dd(1) extensively with SVR3/4, I distinctly remember dd(1) performing the expected behavior. =Brian |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 2006-08-17, bsh wrote:
> > Chris F.A. Johnson wrote: >> bsh wrote: >> > Chris F.A. Johnson wrote: >> > > bsh wrote: >> > > > yuriy_zubarev wrote: > >> $ dd if=txt bs=50 conv=block,noerror,sync | od -c >> 0000020 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 > > Hmmm... What I read in the dd(1) manpage before posting was: > > sync > Pad every input block with NULs to ibs-size; when > used with block or unblock, pad with spaces rather than NULs. It also removes the newlines: $ dd if=~/txt cbs=50 bs=50 conv=block | hd 0+1 records in 7+0 records out 0: 61 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 a 16: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 32: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 48: 20 20 62 20 20 20 20 20 20 20 20 20 20 20 20 20 b 64: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 96: 20 20 20 20 63 20 20 20 20 20 20 20 20 20 20 20 c 112: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 128: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 144: 20 20 20 20 20 20 64 20 20 20 20 20 20 20 20 20 d 160: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 176: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 192: 20 20 20 20 20 20 20 20 65 20 20 20 20 20 20 20 e 208: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 224: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 240: 20 20 20 20 20 20 20 20 20 20 66 20 20 20 20 20 f 256: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 272: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 288: 20 20 20 20 20 20 20 20 20 20 20 20 67 20 20 20 g 304: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 320: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 336: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > Maybe a variant or GNU extension? Possibly. > Once upon a time, using dd(1) extensively with SVR3/4, I distinctly > remember dd(1) performing the expected behavior. And there was no block conversion in SVR3.2 (for which I have a manual). -- Chris F.A. Johnson, author <http://cfaj.freeshell.org> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
![]() |
| Outils de la discussion | |
|
|