AnsweredAssumed Answered

How to remove data from a file up to/after a keyword?

Question asked by britta on Jan 22, 2018
Latest reply on Jan 25, 2018 by andrew_zeikowitz049042

Hi everyone,


I'm having a text file with different structures inside (header data in fixed length, remarks spreading over several lines and item data fixed length again) and need to map this to a proper format (csv or xml). My idea was to do three branches and always delete the data that I don't need for that step - I know some fixed keywords I can look for. Then I do the usual Document Cache and merge the data in a final map.


However, I'm currently stuck with the deletion of the "unnecessary" data. Are there any groovy experts out there who can help me how to set up the script to delete data from my file until or after a certain keyword/string?



My file looks like:


Order Number:   1234

Date:           23/01/2018

Address:        ABC

                Road 12

                88888 City







Item1   UOM1   Price 1


Item2   UOM2   Price2




So for the three different parts I know how to handle them, just not how to handle them together. That's why I came up with the idea with the branches:

1st Branch: delete all data after and including "Remarks:" -> map result as "Header Data"

2nd Branch: delete all data before "Remarks:" and after and including "Items:" -> mas result as "Remarks"

3rd Branch: delete all data before "Items:" -> map results as "Items Data"


I would go for line counting, but I don't know how many lines the address has (there might be an extra line for eg Country), also number of remarks and the description of the items is not fixed.


Any other ideas are welcome.


Thanks a lot,