Hi All…
Good Day:)
I have to convert the csv file into notepad. it has 200 lines, after that I have extract each 20 line from that note pad and each 20 lines save it to the new notepad. That each note pad has to be save in different name
I am having trouble on extracting 20 lines part.
can anyone pls help me with this ?
Thanks In Advance:)
Hi @soundarya_A1 ,
You can try this step
1.read csv to get data table,
2.for each data table with in32 variable count
with 20 to write a text file
I will try a sample for you then send you later
You can try
CSV to TXT.zip (19.1 KB)
regards,
Parvathy
(PS Parvathy)
December 21, 2023, 12:40am
3
Hi @soundarya_A1
Try below way:
1. Read CSV File
- Output: DataTable
2. Assign activity
- Index = 0
- Counter = 1
3. While activity
- Condition: Index < DataTable.Rows.Count
- Body:
a. Write Text File
- File: "Notepad_" + Counter.ToString() + ".txt"
- Text: String.Join(Environment.NewLine, Enumerable.Range(Index, Math.Min(20, DataTable.Rows.Count - Index)).Select(Function(r) String.Join(",", DataTable.Rows(r).ItemArray)))
b. Assign activity
- Index = Index + 20
- Counter = Counter + 1
4. End While
Hope it helps!!
1 Like
ppr
(Peter Preuss)
December 21, 2023, 9:07am
5
is a skip / take pattern
nowadays we can handle (projectcompatibilty: windows) with chunk(Segmentsize)
Illustrating the chunk approach
Reading the file, already split into lines:
Chunk it (kindly note the defensive handling of incomplete segments - Line16-18)
Details:
So, we can:
iterate over the segements with a for each activity
write out the segment with a Write TextFile Activity
Hi @soundarya_A1 ,
The solution will publish in YouTube by tomorrow (22-Dec-2023 at 5PM)
Video Link:- https://youtu.be/UqOqwyuQVjk
Regards,
Pavan kumar
1 Like
sanjay3
(Sanjay)
December 21, 2023, 11:50am
7
Hi @soundarya_A1
->Read CSV File (Output=dt_Data)
->Output DataTable (Output=CSV_Data_
->Write Text File (Input=CSV_Data)
Then
Read that Text File - Var: TextFile
Use Assign Activity
Lines(type: Array of String)=TextFile.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
Use While Loop – Create a Var Name StartIndex(Type: Int32)
Conditaion StartIndex<Lines.Length
Use Assign Activity
Create a string variable called currentLine
currentLine= String.Join(Environment.NewLine, Lines.Skip(startIndex).Take(20))
Use Write Text Activity
"“output_” + (startIndex \ 20).ToString(“D2”) + “.txt”
startIndex = startIndex + 20
1 Like
system
(system)
Closed
December 24, 2023, 11:51am
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.