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

writing to different files

1 view
Skip to first unread message

Stu

unread,
Jun 10, 2009, 9:33:49 AM6/10/09
to
I have a huge input file that needs to be broken up into several
different files in order to over-come a size limitation in another
process.

Can somebody provide me an example of how to do this in AWK. For
example:
My file does not have any new lines in it so I can use split. So each
line must
be 1200 bytes long than I write it out to a file. Once I write 25,000
lines to the first file I want to start writing to a second file,
third file .... until my input is exhasuted.

Thanks in advance for all who answer

pk

unread,
Jun 10, 2009, 10:20:59 AM6/10/09
to

(I assume you mean "can't use" above)

You can use split, of course. See the -b option.
Or you could use dd in a loop, each time starting from a different offset.
But not if you want the \n character at the end of each 1200 bytes line.

Since you're saying "lines", I'm assuning you want the \n after a 1200 bytes
line?

Anton Treuenfels

unread,
Jun 10, 2009, 11:25:43 PM6/10/09
to
It's not clear to me if you mean your input or your output file or both have
no newlines. So I don't know how you're going to block your output into
1200-byte clumps.

But for the other part, essentially what you want to do is change the name
of the output file every 25000 lines. Here's an outline of one way to do it;
you'll have to fill in details yourself

{
outputFile = "myfilename" ++fileCounter # adjust to the conventions of
your locale
for ( lineCounter = 0; lineCounter < 25000; lineCounter++ ) {
# collect 1200 bytes in a variable (I have no idea how you plan to
do this)
print my1200bytes > outputFile # this will put newlines in; use
printf() for no newlines
}
close( outputFile )
}

You'll have to add code to watch for the end of the input file. Unless it's
an exact multiple of 25000 1200-byte lines, you'll have to watch for that
inside the main loop (and then decide what you want to do with that last,
non-1200-byte line).

- Anton Treuenfels

"Stu" <beefs...@hotmail.com> wrote in message
news:dd412a85-0c75-481d...@l28g2000vba.googlegroups.com...

0 new messages