Extracting certain number of lines from notepad

Hi all
My scenario here is I have a text file with more than 500 lines. In need the text from last 20 lines.
Kindly help me with a solution. Thanks in advance

1 Like

Hi @Newton_Rich_SV,
You could create workflow which will scroll down to the bottom of text file. Then it would click last line to move cursor there. And send hot key like Shift + up arrow (20 times) to mark 20 lines.

1 Like

Hi pablito
Thanks for your solution
But it need to be done without opening the notepad

Hi @Newton_Rich_SV,

You can use “Read Text” activity, split the text for every newline into a list and use a loop with index starting from (count of the list-21) till (count of the list -1). You can declare an empty string and use assign inside the loop like emptyString = emptyString+splitList[index]+vbnewline. You can use Enumerable.range(splitList.count()-21,20) inside for each loop. emptyString after the completion of loop will contain the last 20 lines of your text

This method is messy but I guess it’ll suit your requirements.

You can also do this with powershell:

  1. My file looks like this (I specially made number for each line)
    image
  2. Then workflow with script. Tail -5 means that it will catch last five lines. The output of script is kept in output variable. Type Argument for powershell is set to String and IsScript property is marked.
    image
String.Join(Environment.NewLine,output)
  1. And the final effect
    image
1 Like