Skip to Content
avatar image
Former Member

File Split based on Condition

Hello

I have a scenario where I get a file and need to split it into two based on a condition. Is it possible to accomplish this scenario at the file adapter configuration or do I need a mapping for this.

Sample File

-


ABC1234asdfasfasdfasdfsdfasdfsdfsdfsdfasfsdfasdfsfasdfNewafasfsdfasfasdfasfafsdas

asfdasdfasfasdfasdf

asdfasdfadfasdfasfsd asdfsadfa fs

asdfasdfasfasdfasdfasdfadfsfafasfas

ABC1234asfdjoawejasdlfasdfasdfjsdfljasfjsfjaslfjasldfjasdlfsdOldfsdfadsfadfsdfasdffasdfasdfads

asdfasdfsdfa

asfdasdfasdfasdf

asdfsfasfsfsad

fasfasfasdffas

asdfasfsfa

asdfasfasfasdfas

ABC1234asfdjoawejasdlfasdfasdfjsdfljasfjsfjaslfjasldfjasdlfsdNewfsdfadsfsd23424324234234234

asdfsfasdfasfasfasfasfa

asdfasfasdfasfasfaasdfa

in the above content record always start with ABC1234 and it can have multiple sub records and it has a value new or old at column 120-123 in the first line of each record, it can have many sub records but I need to consider ABC1234 as the new record. I need to split the file into two, like one as newdata.txt and other as olddata.txt with new and old records respectively.

Files after the split should look like this

newdata.txt

-


ABC1234asdfasfasdfasdfsdfasdfsdfsdfsdfasfsdfasdfsfasdfNewafasfsdfasfasdfasfafsdas

asfdasdfasfasdfasdf

asdfasdfadfasdfasfsd asdfsadfa fs

asdfasdfasfasdfasdfasdfadfsfafasfas

ABC1234asfdjoawejasdlfasdfasdfjsdfljasfjsfjaslfjasldfjasdlfsdNewfsdfadsfsd23424324234234234

asdfsfasdfasfasfasfasfa

asdfasfasdfasfasfaasdfa

olddata.txt

-


ABC1234asfdjoawejasdlfasdfasdfjsdfljasfjsfjaslfjasldfjasdlfsdOldfsdfadsfadfsdfasdffasdfasdfads

asdfasdfsdfa

asfdasdfasdfasdf

asdfsfasfsfsad

fasfasfasdffas

asdfasfsfa

asdfasfasfasdfas

I appreciate if any one can help me with this.

Thanks in advance

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Dec 28, 2010 at 02:46 PM

    > I have a scenario where I get a file and need to split it into two based on a condition. Is it possible to accomplish this scenario at the file adapter configuration

    No, this is not possible.

    > or do I need a mapping for this.

    Yes, you can do this in a mapping.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 28, 2010 at 08:56 PM

    Hi,

    You can use conditional receiver determination to check the field details (For key value), once it matches you can create 2 different mappings and call them through the interface determination which will take care of the File splits.

    Regards,

    Pavan

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 29, 2010 at 09:13 AM

    Hi,

    as stefan pointed already you can't do this using standard adapter functionality,

    you can do it in mapping easily,convert below code in to UDF it will work.

    String test = "ABCasdasasasABCadsfsddgfgABCggdgdgdgdgABC34343";
    myString =test.split("ABC");
    for(int i=0;i<=myString.length;i++)
    {
    System.out.println("MY STRING " + myString<i>);
    }

    Regards,

    Raj

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 29, 2010 at 04:34 PM

    Yes we can split the content of the file as per requirement using mapping

    Use String's split method to achieve this. You could try StringTokenizer class too.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 29, 2010 at 04:11 AM

    Hi,

    can you explain the scenario? is this file to file scenario?

    regards

    Anupam

    Add comment
    10|10000 characters needed characters exceeded