|
|
Home » Community » Newbie corner » Read txt, analyze and convert to csv
Read txt, analyze and convert to csv [message #53183] |
Sun, 15 March 2020 16:52  |
idkfa46
Messages: 155 Registered: December 2011
|
Experienced Member |
|
|
Hallo guys,
how are you? Maybe someone remember me... I have not been coding for a long time and I'm back to you for an help with my new project.
To speed up a working activity I have to Open a positional TXT, I have to analyse it and export it as a CSV. I'm used to import and elaborate it in Access but the file is everyday bigger and it is going excede Access limits in a short time so I was thinking about a dedicate tool. Is it something I can easy do with UPP?
It is a positional txt with 650 character for line and about 800k lines at the moment (and I have to skip the first and last line)...
Any suggestion about the right approach to the project?
Someone can help me to start this project?
Best regards,
Matteo
|
|
|
Re: Read txt, analyze and convert to csv [message #53192 is a reply to message #53183] |
Tue, 17 March 2020 09:45   |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
you can start with this:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
Vector<String> SpliteLine(String& line)
{
// example
return Split(line, "\t", false);
}
GUI_APP_MAIN
{
String s = LoadFile(TXT_file_path);
StringStream ss(s);
FileOut out(csv_file_path);
while(!ss.IsEof() && !ss.IsError())
{
String line = ss.GetLine();
Vector<String> fields = SpliteLine(line);
if(!fields.GetCount()) continue;
String r = CsvString(fields[0]);
for(int i = 1; i < fields.GetCount(); i++)
r << ";" << CsvString(fields[i]);
r << "\n";
out << r;
}
}
regards
omari.
|
|
|
|
Re: Read txt, analyze and convert to csv [message #53203 is a reply to message #53202] |
Wed, 18 March 2020 17:31   |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
Vector<String> SpliteLine(String& line)
{
ASSERT(line.GetCount() >= 23);
Vector<String> r;
r.Add() = line.Mid(0, 3);
r.Add() = line.Mid(3, 8);
r.Add() = line.Mid(11, 8);
r.Add() = line.Mid(19, 4);
return r;
}
regards
omari.
|
|
|
|
|
|
|
|
|
|
Re: Read txt, analyze and convert to csv [message #53371 is a reply to message #53364] |
Tue, 31 March 2020 15:17   |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
try this solution : (putting '=' at the beginning )
"20200103";="0113E0 ";"SEMICUSCINETTO ";"00000001594";"H ";Common part
"20200103";="0113E1 ";"SEMICUSCINETTO ";"00000001582";"H ";Common part
"20200103";="0113E2 ";"SEMICUSCINETTO ";"00000002264";"H ";Common part
"20200103";="0113E3 ";"SEMICUSCINETTO ";"00000001667";"H ";Common part
"20200103";="0113E4 ";"SEMICUSCINETTO ";"00000001667";"H ";Common part
regards
omari.
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 14:47:52 CEST 2025
Total time taken to generate the page: 0.00797 seconds
|
|
|