How to remove first 3 lines of csv file

Using UI Path Studio - Need to remove first 3 lines of the CSV
tried using activity Remove Data Row but no luck
image

@Rampure_Sachin,

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 :slight_smile:

1 Like

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

@Rampure_Sachin,

You didn’t mentioned this. Clean your data first.

Thanks,
Ashok :slight_smile:

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)

1 Like

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

Hi @Rampure_Sachin

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,

@Rampure_Sachin,

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 :slight_smile:

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