Ever get a gigantic data file that you needed to chop into small pieces for processing, because the next tool you were passing it to just couldn't handle that much at once? Or maybe a server log that somebody forgot to rotate? Here's the easy solution: pass this one-liner the files you need to subdivide (e.g. error_log), and you'll get out bite-sized files labeled error_log.chunk01, error_log.chunk02 and so forth.
Note that a bite is defined in this case to be 10,000 lines: if you want bigger bites, you can always change that number. Also note that bite #100 will be named error_log.chunl00, if you get that high (which you probably don't want to anyway).
perl -pe '$chnk = "chunk01" if 1 == $.; open (STDOUT, ">", $ARGV . "." + . $chnk++) unless ($. - 1) % 10_000; close ARGV if eof' big_file_on +e big_file_two
In reply to Chunk large data/log files into more manageable pieces by ChemBoy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |