Topic
  • 4 replies
  • Latest Post - ‏2013-10-10T12:42:05Z by paul.brett
Jaango
Jaango
77 Posts

Pinned topic Taking values between two string

‏2013-08-29T11:51:11Z |

How do take the value from a file, between two strings? I have one file, which is like START.....................END...............continues.........


How do i define a group which will take from START to END. The number of characters between START and END can vary

  • Jaango
    Jaango
    77 Posts

    Re: Taking values between two string

    ‏2013-08-29T13:17:02Z  

    What I tried was, defined a group, inititor as START then terminator as END, within the group a single item(with one byte) and that item occurs 1:s times. However I understand that this will be wrong as the wtx reads till the end of the file for the 1:s single byte item within the group. I am not sure how to stop checking the singlebyte item, just before 'END'.

  • TarunB
    TarunB
    211 Posts

    Re: Taking values between two string

    ‏2013-09-03T15:27:01Z  
    • Jaango
    • ‏2013-08-29T13:17:02Z

    What I tried was, defined a group, inititor as START then terminator as END, within the group a single item(with one byte) and that item occurs 1:s times. However I understand that this will be wrong as the wtx reads till the end of the file for the 1:s single byte item within the group. I am not sure how to stop checking the singlebyte item, just before 'END'.

    Your idea of using an initiator and terminator appears correct. However, I can't understand why you want to have multiple single byte items in the middle of these - given your requirement to take the whole value between these two strings.

     

    Instead, just create a blob text field that sits in-between the initiator and terminator. So:-

    START

    Blob (1:1) --> this would be an open-ended text field, Minimum size 0, Maximum size unspecified.

    END

     

    Ensure that your input type tree matches the data correctly, and then you'll be able to simply drag out the Blob to your output.

     

    You could, alternatively,  use the WORD function but this is less structured and will lead to a somewhat more complicated output rule. WORD is very useful in its own right, but probably unnecessary in your example.

  • Bhoju
    Bhoju
    37 Posts

    Re: Taking values between two string

    ‏2013-09-05T14:36:01Z  
    • TarunB
    • ‏2013-09-03T15:27:01Z

    Your idea of using an initiator and terminator appears correct. However, I can't understand why you want to have multiple single byte items in the middle of these - given your requirement to take the whole value between these two strings.

     

    Instead, just create a blob text field that sits in-between the initiator and terminator. So:-

    START

    Blob (1:1) --> this would be an open-ended text field, Minimum size 0, Maximum size unspecified.

    END

     

    Ensure that your input type tree matches the data correctly, and then you'll be able to simply drag out the Blob to your output.

     

    You could, alternatively,  use the WORD function but this is less structured and will lead to a somewhat more complicated output rule. WORD is very useful in its own right, but probably unnecessary in your example.

    If every record in the file have START and END, Then you can give a try to below solution

    1. Define item with initiator START and Terminator END no size on this item
    2. Define another item with blob size
    3. Put these two items in sequential group in order 1) and 2).
    4. Put the sequential group into another parent group and mark the sequential group as (0:s)
    5. Map the parent group to the card which reads file.

    So the card when start reading file, will push the data between start and end tags to item1 and rest of the data in item2
    You are repeating these records and you have indexed data in Map now, you can run a functional map in output rule to parse the data further which is captured in item1.

    If the line in your file does not start with START tag, then you have a problem, in that case you need to add one more item on top of item1 with no inititor and terminator as START and make all of them optional. So even if the file have data before START tag in the file, that will go into this newly added field which is marked optional.

    I  hope it helps

  • paul.brett
    paul.brett
    519 Posts

    Re: Taking values between two string

    ‏2013-10-10T12:42:05Z  

    I think the final point to remember is that you also need to ignore the 'continued' garbage at the end.

     

    Please find attached a working Example.

    Attachments