#include <fstream>
#include <optional>
#include <sstream>
#include <string>
#include <vector>
#include "/Users/me/Applications/fmt/include/fmt/core.h"
constexpr std:: size_t minfields{ 33 } ;
std:: optional < std:: vector < std:: string >> splitStr( const std:: string & line,
const char delimiter = ',' )
{
std:: vector < std:: string > splitLine;
splitLine.reserve ( minfields) ;
std:: istringstream ss( line) ;
std:: string buf;
unsigned field{ 0 } ;
while ( std:: getline ( ss, buf, delimiter) ) {
splitLine.push_back ( buf) ;
if ( field == 3 && buf[ 0 ] ! = 'E' && buf[ 0 ] ! = 'T' ) {
return std:: nullopt ;
}
++ field;
}
if ( splitLine.size ( ) < minfields)
return std:: nullopt ;
return splitLine;
}
void copy_selective( std:: istream & in, FILE * out)
{
std:: string line;
while ( std:: getline ( in, line) ) {
auto split = splitStr( line, ';' ) ;
if ( split) {
const std:: vector < std:: string > & vec = split.value ( ) ;
fmt:: print ( out,
"{},{},{},{},{},{},{},{},{},{},{}\n " ,
vec[ 0 ] ,
vec[ 1 ] ,
vec[ 3 ] ,
vec[ 4 ] ,
vec[ 5 ] ,
vec[ 6 ] ,
vec[ 10 ] ,
vec[ 9 ] ,
vec[ 11 ] ,
vec[ 7 ] ,
vec[ 32 ] ) ;
}
}
}
int main( int argc, char * argv[ ] )
{
if ( argc >= 3 ) {
std:: ifstream inFile( argv[ 1 ] ) ;
FILE * outFile{ fopen ( argv[ 2 ] , "w" ) } ;
copy_selective( inFile, outFile) ;
}
}
I2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxvcHRpb25hbD4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+CgojaW5jbHVkZSAiL1VzZXJzL21lL0FwcGxpY2F0aW9ucy9mbXQvaW5jbHVkZS9mbXQvY29yZS5oIgoKCmNvbnN0ZXhwciBzdGQ6OnNpemVfdCBtaW5maWVsZHN7MzN9OwoKc3RkOjpvcHRpb25hbDxzdGQ6OnZlY3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ICAgICAgdmVjWzBdLAogICAgICAgICAgICAgICAgIHZlY1sxXSwKICAgICAgICAgICAgICAgICB2ZWNbM10sCiAgICAgICAgICAgICAgICAgdmVjWzRdLAogICAgICAgICAgICAgICAgIHZlY1s1XSwKICAgICAgICAgICAgICAgICB2ZWNbNl0sCiAgICAgICAgICAgICAgICAgdmVjWzEwXSwKICAgICAgICAgICAgICAgICB2ZWNbOV0sCiAgICAgICAgICAgICAgICAgdmVjWzExXSwKICAgICAgICAgICAgICAgICB2ZWNbN10sCiAgICAgICAgICAgICAgICAgdmVjWzMyXSk7CiAgICB9CiAgfQp9CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKQp7CiAgaWYgKGFyZ2MgPj0gMykgewogICAgc3RkOjppZnN0cmVhbSBpbkZpbGUoYXJndlsxXSk7CiAgICBGSUxFICpvdXRGaWxle2ZvcGVuKGFyZ3ZbMl0sICJ3Iil9OwogICAgY29weV9zZWxlY3RpdmUoaW5GaWxlLCBvdXRGaWxlKTsKICB9Cn0K