How to insert data stored in a variable in an existing CSV file

Hi, folks!

I’m facing an issue. In this repository below, I have a .csv file for each .txt and .pdf file. I’m extracting data from those .txt and manipulating them. How could I insert this taken data to the respective csv? Notice they have the same name “1_1_1.txt” and “1_1_1.csv”.

Best Regards,

Use the Read File activity, and then use the Write CSV activity to write what you read into a variable.

But could I use Write CSV to write the extracted data to an existing CSV? Cause I already have the variables with those datas.

You can, but if you only want to append the data, use Append CSV instead.

1 Like

ARRAY

I’m trying something like. So, for each extracted data in that repository I want to put this data in the respective CSV.

I don’t know if I’m being clear… sorry

Is the data in the text files formatted the same way as CSV? In other words, are you essentially copying the files with a different extension? If so, you can use the Copy File activity, and savethe files with .csv at the end instead of .txt. Both formats are still text files in the end; it’s just that the extension is different.

Not exactly…

The .txt file comes with an OCR text made by another system. I used Regex Matches to extract specific datas from this .txt. Once extracted, I want to insert this in the respective .csv file, like:

1_1_1.txt -> Extracted Data -> 1_1_1.csv
1_1_2.txt -> Extracted Data -> 1_1_2.csv

In the A1 cell of each .csv I already have datas that came from the other sistem (Kodak) and the A1 cell of each .csv file is coming like this:

Data1|Data2|Data3 so on…

I want to append the extracted data (variables) to this A1 cell in each csv file

Thanks in advance for being helping me

I had forgotten that Append CSV requires a datatable. Use Append File instead, and you’ll be able to append the raw string to the end of the file.

Append Line, isn’t it?

Yes, that’s the one (mistyped in the previous post).

Ok, got it. But, how would the robot know that it has to insert the data in the A1 cell?

Excel interprets text-based CSVs itself and knows that the first item goes to cell A1.

1 Like

This was the result, it made it in the A3 and appended the only the data extracted from my last file extraction.

How could I put a rule to do this? 1_1_1.txt -> Extracted Data -> 1_1_1.csv

I think the missing step is how to filter the data when going from 1_1_1.txt to 1_1_1.csv. How are you trying to filter the data?

1 Like

I’m thinking right know about how will I do it. Do you have any suggestion?

I thought of something like:

I- Get the first extraction
II- Insert in the first .csv

But I have a for each activity for the txt extractions already. I know what has to be done but I’m completely lost about how to execute it

You could just use this if you have an array of lines you want to add to the csv:
File.WriteAllLines("C:\temp\myFile.csv", myLines)

1 Like

You’ve made yourself clear enough. Thank you!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.