By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,541 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,541 IT Pros & Developers. It's quick & easy.

file seperation

P: 12
ok i am trying to seperate a single large .doc file into smaller individual .doc files the first script worked as the files had a common start and end line ABC....DEF... so seperation was prety easy. the second file has common start lines but not end lines is there a way i can have it look at the top line and referance the bage break befor it for the end line here is what i have so far
Expand|Select|Wrap|Line Numbers
  1. open (IN, 'te26085807.doc'); 
  2. open (OUT,'>>te_1');
  3. $outcount = 1;
  5. while (<IN>)
  8.     print OUT;
  10.        if ( $_=~/Certification of Duty for/ )
  11.         {
  14.             $UIC = substr $_, 42, 5;     # extract the UIC for file name
  16.         }
  18.         if ( $_=~/Top line of next document/ )
  19.         {
  21.             close (OUT,'>>te_$outcount');
  23.             rename ("te_$outcount","/xxxx/xxxxx/xxx/xxxxx/NAME$UIC.doc");
  25.             $outcount++;
  27.             open (OUT,">>te_$outcount");
  28.         }
  29.         }
Nov 26 '08 #1
Share this Question
Share on Google+
2 Replies

P: 13
Try reading the beginning of file first before opening filehandler and print the line out. You can use/set a flag to determine if a filehandler is open. While reading the file content, whenever the line matches the beginning of file, check if the output filehandler is open.
1) If yes, close it, rename the file as you wish, increase your output file count... etc, open a new file for printing. (this will take care of the 2nd output file onwards)
2) If no, open a new file for printing. (this will take care of the 1st output file)
This way, you do not really need to worry about the pattern matching for the end of file.
Nov 28 '08 #2

P: 12
where can i find some sample scripts on this
Nov 28 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.