Skip to main content

How to remove the last line in flat file using Arc script ??

The below script is to add the “END” on the last line but I need to remove the END which is present in the last line of a Flat-file??

<arc:set attr="file.file" value="afilepath]" />

<arc:call op="fileRead" item="file">
  <arc:set attr="tmp.originalBody">dfile.file:data]</arc:set>
</arc:call>

<arc:unset attr="output.data">ttmp.originalBody]END</arc:set>
<arc:unset attr="output.filename" value="940_enow()]" />
<arc:push item="output" />

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" />

 


Reply