Skip to content

Instantly share code, notes, and snippets.

@tristian2
Created August 3, 2016 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristian2/8b72eec8e75e711e9773ce169f3dd2b4 to your computer and use it in GitHub Desktop.
Save tristian2/8b72eec8e75e711e9773ce169f3dd2b4 to your computer and use it in GitHub Desktop.
Preplog.cpp
/*
****************************************************************
* File: preplog.cpp
* Author: David Grant(MS)
* Purpose: Removes lines beginning with "#" from an input
* text file
* Written to remove header lines from IIS
* web logs for BULK IMPORT to SQL
*
* Disclaimer: This code is to be used for sample purposes only
* Microsoft does not gaurantee functionality
*
* Latest Revision: 03/29/2001
*
****************************************************************
*/
#include <stdio.h>
#include <string.h>
int main(int argc, char **argsch)
{
FILE *stream;
char line[10000];
int ch;
bool headerRow = true;
if(argc < 2)
{
printf("Usage: preplog.exe <weblog>\n");
printf("\nThe output will go to stdout, so use > filename to direct to an output file\n");
return -1;
}//if
if( (stream = fopen( argsch[1], "r" )) != NULL )
{
while(fgets(line,10000,stream) != NULL)
{
if(ch = strncmp(line,"#Fields: ",9) ==0)
{
if (headerRow)
{
char *pstr1;
pstr1 = &(line[9]);
printf( "%s", pstr1);
headerRow=false;
}//if
}//if
else {
if(ch = strncmp(line,"#",1) !=0)
{
printf( "%s", line);
}//if
}//else
}//while
fclose( stream );
return 0;
}//if
else
{
printf("Could not open %s. Please ensure that the path and filename are correct.\n",argsch[1]);
return -1;
}//else
}//main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment