Remove lines in a text file

can you pls share the xaml file? I am using read text file activity for reading the .txt file, then saving the op …then using the above code of yours, getting errors. Any specific data type for arrval?

please have a look at the below screenshot

image

Hi @shreyaank,

What error you are getting??

Try below code

arrval=strtext.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries)

disallows implict conversion from string to char… my variable arrval is set as string

for this code, im getting cannot convert from system.string to system.string in Assign

Hi @shreyaank,

What is that exception can you send the screenshot

arrval=strtext.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries)

arrval=arrval.Skip(3).ToArray()

Regards,
Arivu

arrval is of which data type?

String

Regards,
Arivu

can you please share the xaml file where in you are removing the first three lines of a text file??

I used a somewhat different method but the attached XAML shows one way to accomplish this.

Happy to explain how it works if you have any questions.

RemoveXLinesFromTextFile.xaml (9.7 KB)

1 Like

Thank you Tyler, Will check and get back soon

Thanks a lot Tyler! This works PERFECTLY! :slight_smile: Thank you so much

HI Tyler,

Suppose i want the same code to pick as many as 15 .txt files from the same folder and delete just the first three rows for each, should i make any changes then?

I tried using for each item in a folder, the code doesnt seem to work right, bot is replicating/copying the content in the first txt file to the rest of the files.

Below should accomplish removing the same number of lines from every text file in a selected folder. You can easily replace the prompts for another method of specifying the folder and number of lines to be removed if you wish.

RemoveXLinesFromAllTextFiles.xaml (13.8 KB)

1 Like

hi, some missing activities while opening the xaml. can you please share the activities.

Hello, Can anyone help how we can remove last line from text file?

Thanks in advance.

Hi @Jainsweety,

You need to read the text file using read text file activity.

Then split the string using environment.newline, it will give you string of lines
Then in a write text file activity you need to write as
(lines.Take(lines.Length - 1))
Before that delete the text file.

Thank you !!

Were you able to figure out the missing activities?

HI,
Here is a package to manage the text files. It has many activities to make use the automation .

Regards
Balamurugan.S