Hi @bala_bk
If you only want to remove the last line from a flat file without shifting it to the second-to-last line, you can use the following script.
In this script:
- first count the total number of lines using the
fileReadLine operation. I initialize a total (total lines) variable to 0 and increment it by 1 for each line during iteration. - In the second part, I print the data. If the index is less than the total number of lines, the corresponding data is printed.
This approach ensures the last line is excluded without affecting the rest of the file.
Here is the script:
<arc:set attr="file.file" value="[filePath]" />
<arc:set attr="file.total" value="0" />
<!-- Counting total number of lines present in the file -->
<arc:call op="fileReadLine" in="file" out="line">
<arc:set attr="file.total" value="[file.total | add(1)]" />
</arc:call>
<!-- printing the data less than the size of total lines variable, in order to remove the last line -->
<arc:set attr="output.data">
<arc:call op="fileReadLine" in="file" out="line">
<arc:if exp="[_index] < [file.total]">[line.file:data]\n</arc:if>
</arc:call>
</arc:set>
<arc:push item="output" />
Do let me know if it works or if you have more questions.