Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split text file at pattern

Status
Not open for further replies.

tbalazs

IS-IT--Management
Dec 18, 2000
158
GB
I would like to split an ASCII file into smaller files (could be named 1.txt 2.txt, doesn't matter) based on the occurrence of a pattern (say immediately before each "abcde"). Any ideas how I could do this?
Thanks.
Tony.
 
open(LOG, "path/filename");
$/ = undef;
$string = <LOG>;
close(LOG);

@pages = split(/abcdf/, $string);

$count = 0;
foreach $item (@pages){
open(FILE, "$count.txt");
print FILE "$item";
close(FILE);
$count++;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top