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
> 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
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
Thanks again.
Jean-Pierre Radley <j...@jpr.com> wrote in article
<1999020412...@jpradley.jpr.com>...
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>...
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.
:-)
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..