Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

need file manipulation command

1 view
Skip to first unread message

Shane Faulkner

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to
Hoping someone can help with this.

I have an ascii file with no end of record terminators. It's just one long
stream
of data from Unix's perception.

What I need to do is read 756 bytes at a time, append a fixed number of
spaces
(say 200 for example), append a carriage return/linefeed and write to
another
file.

Anyone? Thanks in advance.

--
Shane Faulkner
ak...@freenet.buffalo.edu

Tony Lawrence

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to Shane Faulkner
Shane Faulkner wrote:

> I have an ascii file with no end of record terminators. It's just one long
> stream of data from Unix's perception.
>
> What I need to do is read 756 bytes at a time, append a fixed number of
> spaces (say 200 for example), append a carriage return/linefeed and write to
> another > file.


Piece of cake :-)

First, to convert to lf every 756 characters:

dd if=yourfile of=newfile conv=unblock cbs=756

The next step is to add whitespace. Good old awk can always do that if
it's text:

cat newfile | awk '{ printf "%-956s\n",$0 }'

Combine these together with
dd if=yourfile conv=unblock cbs=756 | awk '{ printf "%-956s\n",$0 }' >
somewhere


Test with small files first to avoid typos.

(dd can get a small file from your big file:

dd if=yourfile of=smallfile bs=756 count=3

)
Loads of fun :-)

--
Tony Lawrence (to...@aplawrence.com)
SCO ACE
SCO articles, help, book reviews: http://www.aplawrence.com

Jean-Pierre Radley

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to
Shane Faulkner averred (on Thu, Feb 04, 1999 at 04:11:14PM +0000):

| Hoping someone can help with this.
|
| I have an ascii file with no end of record terminators. It's just one long
| stream
| of data from Unix's perception.
|
| What I need to do is read 756 bytes at a time, append a fixed number of
| spaces
| (say 200 for example), append a carriage return/linefeed and write to
| another
| file.

dd if=your_input_file conv=unblock cbs=756 2>/dev/null |
awk '{printf "%-956\r\n", $0}' > your_output_file

But why the carriage return?

--
Jean-Pierre Radley <j...@jpr.com> XC/XT Custodian Sysop, CompuServe SCOForum

Shane Faulkner

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to
Thanks to Jean-Pierre and Tony.... forgive my ignorance,
but which part of the command you gave me indicates
200 spaces??

Thanks again.

Jean-Pierre Radley <j...@jpr.com> wrote in article
<1999020412...@jpradley.jpr.com>...

Logan McLeod

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to
>awk '{printf "%-956\r\n", $0}' > your_output_file


The awk command provides the whitespace notice the number 956 breaks quite
nicely to 756 (Original rec length) + 200 (Whitespace)...

Logan

Shane Faulkner wrote in message
<01be506d$c0a13400$0701...@blackmagic.qbcwinnt>...

Jean-Pierre Radley

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to
Shane Faulkner averred (on Thu, Feb 04, 1999 at 06:29:51PM +0000):

| Thanks to Jean-Pierre and Tony.... forgive my ignorance,
| but which part of the command you gave me indicates
| 200 spaces??
|
| Thanks again.
|
| Jean-Pierre Radley <j...@jpr.com> wrote in article
| <1999020412...@jpradley.jpr.com>...
| > dd if=your_input_file conv=unblock cbs=756 2>/dev/null |
| > awk '{printf "%-956\r\n", $0}' > your_output_file


Note that except for my including the carriage return (again -- what
for??) Tony and I dashed off exactly the same solution.

The dd command makes 756-character lines out of your input.

The awk command writes each line out as a right-padded-with-spaces line
of 956 characters.

:-)

Tony Lawrence

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to Shane Faulkner
Shane Faulkner wrote:
>
> Thanks to Jean-Pierre and Tony.... forgive my ignorance,
> but which part of the command you gave me indicates
> 200 spaces??

awk '{printf "%-956\r\n", $0}'

It's 756 + 200 that causes the 956..

Oh, and my version only gave you linefeeds; jpr's gave you lf and
carriage returns.

Otherwise they were identical..

0 new messages