Hello Gabriele,
For your request, we would need to know the number of lines that you would like to delete. Based on your example, I hard coded the number of 3 to eliminate from the list.
However, AutoMate will gather the data internally, manipulate it, then write back to the file. We suggest creating a temp file to write the newly edited information, then deleting the original file and renaming the temp file, or overwriting the original file altogether. Here is an example of how to accomplish your goals up to the file replacement. Please place your example file onto your desktop:
<AMVARIABLE NAME="varNew" />
<AMVARIABLE NAME="varCounter" VALUE="0" />
<AMVARIABLE NAME="varItem" />
<AMVARIABLE NAME="varRead" />
<AMFILESYSTEM ACTIVITY="read_file" FILE="%GetDesktopDirectory%\Myfile.txt" RESULTVARIABLE="varRead" />
<AMLOOP ACTIVITY="list" LIST="%varRead%" DELIMITER="new_line" RESULTVARIABLE="varItem" />
<AMIF EXPRESSION="%varCounter% = 3" />
<AMFILESYSTEM ACTIVITY="write_file" FILE="%GetDesktopDirectory%\Myfiletemp.txt">%varItem%</AMFILESYSTEM>
<AMLABEL ACTIVITY="goto" LABELNAME="write" />
<AMIF ACTIVITY="end" />
<AMTEXT ACTIVITY="replace" TEXT="%varItem%" FIND="%varItem%" REPLACE="" RESULTVARIABLE="varNew" />
<AMVARIABLE ACTIVITY="increment" RESULTVARIABLE="varCounter" />
<AMLABEL LABELNAME="write" />
<AMLOOP ACTIVITY="end" />
As you can see, I used a counter to let AutoMate know how many times I deleted a row. Once that number gets to 3, then it begins writing the rest to the temp file. I used a label to skip over the deletion of the unnecessary lines once the counter is at 3.