That's a cool perl one-liner.
Here's an implementation in C: <use at your own risk!>
============
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp;
char *filename;
char buffer[2];
int c;
/* Check commandline arguments */
if (argv[1] == NULL){
printf("\nUsage:\n");
printf("./convert [infile] > <outfile>\n");
exit(1);
} else {
filename=argv[1];
}
/* Open the file */
if ((fp = fopen(filename, "r")) == NULL)
{
printf("\nCould not open file %s.\n\n", filename);
exit(1);
}
/* set counter */
c=1;
/* read the flatfile one char at a time */
while (fgets(buffer, 2, fp) != NULL) {
printf("%c",buffer[0]);
/*
These are the places where the delimiter should be.
In my example flat file, I have those after the 10th,
20th, and 27th character read.
*/
if (( c == 10 ) || (c == 20) || (c == 27 )){
printf(";");
}
c += 1;
/*
We should check for the end of the line and reset our counter.
*/
if (c == 39){
c=1;
}
}
/* Close the file */
fclose(fp);
}
=======================
Here's the flatfile I used for the above:
-------
janapin michael 123456 10-11-1974
silas zbcxtrthrm123456701-02-2003
davinci leonardo 432 04-21-1976
esttra etratatot 3 03-04-2006
-------
It's quick and dirty. So someone here might optimize that better.
Enjoy!
Mhac
_________________________________________________ Philippine Linux Users' Group (PLUG) Mailing List [email protected] (#PLUG @ irc.free.net.ph) Read the Guidelines: http://linux.org.ph/lists Searchable Archives: http://archives.free.net.ph

