Delete First Two Lines and last line in TXT File


How can I delete first two lines and last line in TXT/Note pad file.


Hello @minal.patil ,

Can you share the input file here.

Hi @minal.patil

You can try this approach


String.Join(Environment.NewLine, strText.Split({Environment.NewLine}, StringSplitOptions.None).Skip(1).Reverse.Skip(1).Reverse)

Refer the xaml

DeleteFirstAndLastLine.xaml (4.8 KB)

a flip flap approach:
arrLines = File.ReadAllLines(“YourPath”).Skip(2).Reverse()Skip(1).Reverse().ToArray

then write it back to text file with:


OR (similar to Varuns approach)
strFlatten = String.Join(Environment.NewLine, arrLines)
using strFlatten for Write text file activity

1 Like

May we ask you the following: when the main building block from your selected solution was the flip-flap logic: Skip(2).Reverse()Skip(1).Reverse().ToArray then please flag @kumar.varun2 (instead of me) for the solution as he gave it first as an answer. Thanks

1 Like