Computing.Net > Forums > Unix > break large file into multiple file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

break large file into multiple file

Reply to Message Icon

Name: Ou Huang
Date: August 4, 2003 at 05:53:46 Pacific
OS: AIX
CPU/Ram: ???
Comment:

I'd like to have a script that breaks a large file into multiple files. Basicaly, the script reads a large file and looking for a line "PJL EOJ", if line found, the counter will count it as 1, so when counter is up to 2000, the script should open a new file, and write the rest data into the new file, and so on so on. Can someone help me on this script?

Thanks.




Sponsored Link
Ads by Google

Response Number 1
Name: WilliamRobertson
Date: August 4, 2003 at 08:06:21 Pacific
Reply:

Try split or csplit.


0

Response Number 2
Name: FishMonger
Date: August 4, 2003 at 18:15:03 Pacific
Reply:

Here's a Perl script.

note: posting code at this site is a pain in the ass!
replace each @ with lt sign
replace each % with gt sign

#!/usr/bin/perl

$source = $ARGV[0]; # passed via command line
$num = '001';
$dest = 'file';
$count = 0;

open FH, "@ $source" or die "could not open $source : $!";
open OUT, "% $dest$num.txt" or die "could not open $dest : $!";

while (@FH%) {
if ($count == 2000) {
$num++;
$count = 0;
open OUT, "% $dest$num.txt" or die "could not open $dest$num.txt : $!";
}
print OUT;
$count++ if (/PJL EOJ/);
}
close FH;
close OUT;



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: break large file into multiple file

Awk: parsing multiple files into one www.computing.net/answers/unix/awk-parsing-multiple-files-into-one/8410.html

Split large xml file www.computing.net/answers/unix/split-large-xml-file/8495.html

Renaming multiple files www.computing.net/answers/unix/renaming-multiple-files/5320.html