I have to read the content of an existing file "operativedata.txt" line by line and write this data into an excelsheet "datawarehouse.csv" line by line. The content of the file "operativedata.txt" looks like following in the picture (operativedata.txt)):
The data in operativedata.txt have to be written transformed in a different way to datawarehouse.csv. It have to look like this in the csv file:
"date;time;randomvalue\n" \n means after these three lines do a return
This type of format have to be written (all 10 seconds) in the datawarehouse.csv file. It should look like this at the end: datawarehouse.csv
Code for generating datawarehouse.csv:
using System;
using System.IO;
using System.Threading;
namespace etltxt2csv
{
class Program
{
string[]content;//Array for reading each line of the file operativedata.txt
public void loop()
{
content = File.ReadAllLines(@"C:\ETL-Process\operativedata.txt");//File to be Read
while (true)
{
for (int i = 0; i < content.Length; i++)
{
Thread.Sleep(10000);
File.AppendAllText(@"C:\ETL-Process\datawarehouse.csv", content[i] + ";" + "\n");
Console.WriteLine(content[i]);
}
}
}
static void Main(string[] args)
{
Program a= new Program();
a.loop();
}
}
}
operativedata.txt was created with the following code:
using System;
using System.Threading;
using System.IO;
namespace createData
{
class Program
{
string file, date, time;
int randomValue;
public void createFile()
{
file = @"C:\ETL-Process\operativedata.txt";
date = DateTime.Now.ToString("yyMMdd");
time = DateTime.Now.ToString("HHmmss");
Random random = new Random();
while (true)
{
randomValue = random.Next(200);
Thread.Sleep(10000);
File.AppendAllText(file, "\r\n" +date + "\r\n" + time + "\r\n" + randomValue);
}
}
static void Main(string[] args)
{
Program a = new Program();
a.createFile();
}
}
}
What do I have to change in the code of etltxt2csv so that the data can be written transformed in this way:
"date;time;randomvalue\n" (always the first three lines in then the next three lines with a return \n)
into the file datawarehouse.csv ?
When I'm executing the code of etltxt2 I listed here, the Output of my excel file is not transformed like above in the picture (datawarehouse.csv)