PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Re: File re-format
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Re: File re-format

Réponse
 
LinkBack Outils de la discussion
Vieux 17/08/2006, 22h07   #1
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File re-format


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

  Réponse avec citation
Vieux 17/08/2006, 22h27   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File re-format

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
  Réponse avec citation
Vieux 17/08/2006, 22h37   #3
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File re-format


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

  Réponse avec citation
Vieux 17/08/2006, 23h01   #4
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File re-format

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
  Réponse avec citation
Vieux 17/08/2006, 23h12   #5
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File re-format


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

  Réponse avec citation
Vieux 18/08/2006, 02h25   #6
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File re-format

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h01.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,19288 seconds with 14 queries