Using UI Path Studio - Need to remove first 3 lines of the CSV
tried using activity Remove Data Row but no luck
Read CSV To Datatable
Use assign activity to skip first 3 rows.
dtInput=dtInput.AsEnumerable.Skip(3).CopyToDataTable
This will remove the first 3 rows.
Thanks,
Ashok
In that CSV file – first 2 lines have normal text , 3rd line is empty, 4th line is actual header line, 5th line onwards actual data to be processed.
used assign option with stated clause by [ashokkarale]
getting following error , same error use to get using Remove Data Row activity too
that’s why I have to delete the first 3 rows from that CSV file but that is not happening through different approach …in call activity I am getting same error.
Assign Activity
arrLines | datype: String Array =
File.ReadAllLines(yourFilePath).Skip(3).ToArray
Then Post process it eg with generate datatable or write IT Back to File
Making a flat String we can so
String.Join(Environment.Newline, arrLines)
Yes …I have to remove first 3 lines from CSV file …then process real data
r u asking me to read content of CSV file as normal String array instead of datatable ?
Yes, you can not read csv as datatable if input file is not properly formatted
Can you try like below
1. Read Text File
- File Path: "path/to/your/csvfile.csv"
- Output: csvContent
2. Assign
- To: linesArray
- Value: csvContent.Split({Environment.NewLine}, StringSplitOptions.None)
3. Assign
- To: remainingLines
- Value: linesArray.Skip(3).ToArray()
4. Assign
- To: updatedContent
- Value: String.Join(Environment.NewLine, remainingLines)
5. Write Text File
- File Path: "path/to/your/csvfile.csv"
- Text: updatedContent
Regards,
Here is the logic to remove first 3 not needed rows and then read the remaining csv.
Sample project:
CSV Ops.zip (3.0 KB)
Thanks,
Ashok
We can read the CSV Data, which is string, as String, or read the lines into a String Array
Then we cleanse
After that, IT can be parsed or post-processed as needed