It’s a little difficult to tell from your question, what it is you want to achieve, but likely you’d want to use a regular expression in a regex replacement.
It sounds like you want to take a flat file with a freestanding END line:
This is a test.
Second line.
END
And move END to the end of the previous line:
This is a test.
Second line.END
Regular expressions are powerful ways to manage pattern matching, and you can use Regexr to test out new patterns. That code, combined with your existing setup, would look something like:
<arc:set attr="file.file" value=".filepath]" />
<arc:call op="fileRead" item="file">
<arc:set attr="tmp.originalBody">gfile.file:data]</arc:set>
</arc:call>
<arc:set attr="output.data">ttmp.originalBody | regexreplace('\s+END$','END')]</arc:set>
<arc:set attr="output.filename" value="940_enow()]" />
<arc:push item="output" />
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="vfilePath]" />
<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="vfile.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="f_index] < ]file.total]">lline.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.