0

I have a source data file which I have been using JREPL.BAT to perform some very simple search and replace operations quite successfully. I now need to expand on that to do 2 jobs. 1. remove all lines that start with the string "appX_formContent". This line contain a lot of html output also, it all needs to be deleted on that line. 2. remove all lines that start with "Hex Payload:" and the subsequent line that comes with it.

This is an example of the input data file which shows 2 records. The delimiter between each record is the row that contains "-----------------".

-----------------
Message Headers
  JMSCorrelationID: 60bb7750-e9e2-11e9-98bb-42010a961307
  JMSPriority: 4
  JMSRedelivered: false
Message Properties
  app_trackingId: 190990a2-d8d8-43eb-814a-36ceba7a9111
  appX_formInstanceIdentifier: FRM389083
  appX_formContent: {"data":{"C7d14a6eb-70e7-402d-9d6e-4efd01ba561c":"N","Y","test.</p>\n<p>test form data&nbsp;to be informed&nbsp;</p>\n<p>...............</p>\n<p><strong>Update</strong></p>\n<p><strong>years</strong>"<p>supervision</p>","<p>:true,"c9377ae2-901d-4461-929c-c76e26dc6183":false}}}
  app_sourceSystemId: source
  app_eventCode: FORM_OUTPUT
  app_instigatingUserId: 66
  JMSXGroupSeq: 0
Hex Payload:
25 50 44 46 2D 31 2E 35 0D 0A 34 20 30 20 6F 62 6A 0D 0A 3C 3C 2F 54
-----------------
Message Headers
  JMSCorrelationID: 641a80d0-e9e2-11e9-98bb-42010a961307
  JMSPriority: 4
  JMSTimestamp: 2019 10 08 16:43:40
  JMSRedelivered: false
Message Properties
  app_trackingId: a3c2fe93-ef71-4611-9605-9858ff67a6e8
  appX_formInstanceIdentifier: FRM388843
  appX_formContent: {"data":{"C7d14a6eb-70e7-402d-9d6e-4efd01ba561c":"N","Y","test.</p>\n<p>test form data&nbsp;to be informed&nbsp;</p>\n<p>...............</p>\n<p><strong>Update</strong></p>\n<p><strong>years</strong>"<p>supervision</p>","<p>:true,"c9377ae2-901d-4461-929c-c76e26dc6183":false}}}
  app_sourceSystemId: source
  app_eventCode: FORM_OUTPUT
  app_instigatingUserId: 433
  JMSXGroupSeq: 0
Hex Payload:
25 50 44 46 2D 31 2E 35 0D 0A 34 20 30 20 6F 62 6A 0D 0A 3C 3C 2F
-----------------

This is the batch file that I use to call jrepl - very simple.

call jrepl ".*(?:appX_formContent: .*)" "" /m /f "inpu.txt" /o "output.txt"

I've only tried to remove the appX_formContent line with the regex but it isn't producing any output. I'm not good with regex so help appreciated. Not sure how to handle the second task of deleting the Hex Payload: line.

dbenham
  • 127,446
  • 28
  • 251
  • 390
zoomzoomvince
  • 239
  • 1
  • 5
  • 14
  • 1
    Seems like a boolean operator would do the trick. `^(.*appX_formContent:.*|Hex Payload:\n.*)$` – MonkeyZeus Jan 31 '20 at 20:37
  • The boolean would seem very logical but when I use that with jrepl which I get is 1. a blank line where the appX_formcontent was previously 2. The Hex: line is still present plus the line after it. call jrepl "^(.*appX_formContent:.*|Hex Payload:\n.*)$" "" /m /f "in.txt" /o "out.txt" – zoomzoomvince Feb 01 '20 at 13:49
  • I think I found the issue - I needed to use \r\n instead of \n after the "Hex Payload" part. It is now removing the line after the Hex Payload correctly. – zoomzoomvince Feb 01 '20 at 18:54
  • 1
    I see. You could use `^(.*appX_formContent:.*|Hex Payload:[\r\n]+.*)$` to make it the most resilient. – MonkeyZeus Feb 03 '20 at 13:41
  • Thank you MonkeyZeus , all working perfectly now. – zoomzoomvince Feb 03 '20 at 15:09
  • I would use `\r?\n` so that it works with both Windows and 'nix formatted lines – dbenham Mar 11 '20 at 21:39

0 Answers0