As it turns out, this should be fast, all around. It appears the 5 letters per row data, is a 5 letter permutation list. Since I didn't have enough sample data to work with, I generated my own list, up through AZZZZ - that took just a couple seconds.

Which made me think that maybe re-generating the entire permutation file, WITH these extra 5 char's we're trying to prepend, would take less time than coding up a prepending program with the file handling the OP wanted, etc.

In any case, this is only slightly tested for accuracy, and not optimized, or tested against other algorithms or data structures. I avoided using strcat, because I thought it would be a slow down, and wasn't necessary. It's fast enough, imo - about 2.2 Million records prepended, in about 2.5 seconds.

As Brafil mentioned earlier in the thread, it's running speed is largely bound by the IO throughput.

Code:
/* 
prepends 3 char's from perms3.txt file, (which has 5 rows of char's), 
each row having 3 char's and a newline we don't use. These are 
written out into the front of each row before the 5 chars 
(6 counting the newline), in the perms6.txt file, are written out
to five sequentially numbered files, (allperm1.txt - allperm5.txt).

It's not optimized, or tested against other algorithms, but it's fast. 
Try it and C. ;)

*/

#include <stdio.h>

typedef struct {
  char char3[3];
  char newline;
}record;

int main(void) {
  FILE *fpin3, *fpin6, *fpout;
  int i;
  const char *filename6="perms6.txt"; //reminder to take the newline char #6
  const char *filename3="perms3.txt";//leave the newline behind
  char fileOut[]="allperm1.txt";
  record rec;
  char char6[6];
  unsigned long int count = 0;

  fpin3 = fopen(filename3, "rt");
  fpin6 = fopen(filename6, "rt");
  if(fpin3 == NULL || fpin6 == NULL) {
    printf("\nError opening input files");
    return 1;
  }
  if((fpout =fopen(fileOut, "wb"))== NULL) {
    printf("\nError opening output file");
    return 1;
  }
  printf("\n\n\n");
  for(i=0;i<5;i++) {
    fread(&rec, sizeof(rec), 1, fpin3);
    
    while(fread(char6, 6, 1, fpin6) >0) {
      fwrite(rec.char3, 3, 1, fpout);     //fpout or stdout (for debug)
      fwrite(char6, 6, 1, fpout);         //ditto
      ++count;
      //getch();
    }
    if(fileOut[7]=='5')
      break;
    rewind(fpin6);
    fclose(fpout);
    printf("\n closing file %s", fileOut);
    fileOut[7]++; //increment the file number in the name
    printf("\n opening file %s", fileOut);
    if((fpout =fopen(fileOut, "wb"))== NULL) {
      printf("\nError opening output file");
      return 1;
    }
  }
  fcloseall();
  printf("\n\n %lu\n\t\t\t    press enter when ready", count);
  i=getchar();
  return 0;
}