Remove lines in a text file

Hi all,

I wanna remove first three lines in a txt file. i have around 10 files for which first three lines have to be removed for all. please suggest an approach

Hi,
Do you want to remove first 3 empty lines… or…?

No those are not empty lines, I just need to remove first three lines as they contain unwanted text. And it is a .txt file.

Hi @shreyaank,

Arrval=Strtext.Split(Environment.Newline)

Arrval.RemoveAt(1)
Arrval.RemoveAt(2)
Arrval.RemoveAt(3)

Regards,
Arivu

1 Like

will the above code remove just the first three lines in a .txt file?

Yes

Regards,
Arivu

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)

1 Like

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