vsmeruga has asked for the wisdom of the Perl Monks concerning the following question:

Dear perl gurus I need help with a command or script to merge 2 lines where ever we find the string. I am not sure how to attach a scanned document here. First line has string value: VSIN, immediate line has value: SETTLEMENT Where it finds the 2 string values in the whole file, one below the other, those 2 lines to be merged into a single line and the other detail data lines has to be remained in the same order.

Eg: Line1: VSIN .... (Space) SETTLEMENT CURRENCY .... Line2: other detail data in the same order Line3: VJRE ... Line4: VJRE ... Line5: VSIN .... (Space) SETTLEMENT CURRENCY .... Line6: VJRE .... Line7: VJRE .... Line8: VJRE... Line9: VSIN. ...(Space) SETTLEMENT CURRENCY.... .... .... Many thanks Your help is much appreciated as I am not a perl programmer.

Sheku

Replies are listed 'Best First'.
Re: Merging 2 lines based on a string
by vinoth.ree (Monsignor) on Feb 05, 2015 at 03:22 UTC

    Hi vsmeruga,

    Please show us what you have tried so for? So that we can help you better to write the code by yourself.

    Moreover give us the sample output format.


    All is well
      Hi vinoth I gave you the output in my post.
      My inputfile will be like below
      VSIN : VJ000A0WCCX5 ACCOUNT TYPE : VJ SETTLEMENT CURRENCY : USD TRADE DATE : 22-01- +12 VJRE 1556522 1 0234000759762 S 30-01-14 15,000,000.000- + 15,000,000.00 0.290000 73,506.94 VETS VJRE 1556524 1 0234000759763 S 30-01-14 15,000,000.000- + 15,000,000.00 0.290000 73,506.94 VETS VSIN : VJ000A0WCCX5 ACCOUNT TYPE : VJ SETTLEMENT CURRENCY : USD TRADE DATE : 23-04- +14 VJRE 1022786 1 0234000790324 S 25-04-14 85,000,000.000- + 15,000,000.00 0.300000 63,750.00 VETS VJRE 1022788 1 0234000790325 S 25-04-14 85,000,000.000- + 85,000,000.00 0.300000 63,750.00 VETS VJRE 1022790 1 0234000790326 S 25-04-14 85,000,000.000- + 85,000,000.00 0.300000 63,750.00 VETS VSIN : VJ000A0WCCX5 ACCOUNT TYPE : VJ SETTLEMENT CURRENCY : USD TRADE DATE : 25-04- +14 VJRE 1024906 1 0234000791296 S 30-04-14 75,000,000.000- + 75,000,000.00 0.310000 59,201.39 VETS VJRE 1024908 1 0234000791297 S 30-04-14 75,000,000.000- + 75,000,000.00 0.310000 59,201.39 VETS VSIN : VJ000A0WCCX5 ACCOUNT TYPE : VJ SETTLEMENT CURRENCY : USD TRADE DATE : 28-04- +14 VJRE 1026070 1 0234000791843 S 30-04-14 90,000,000.000- + 90,000,000.00 0.330000 167,291.67 VETS ISIN : VJ000A1ABC49 ACCOUNT TYPE : VJ SETTLEMENT CURRENCY : USD TRADE DATE : 05-01- +15 VJRE 1812943 1 0234000874452 B 07-01-15 8,500,000.000 + 8,771,500.41- 0.150000- 139.17- VETS ISIN : VJ000A1ABC49 ACCOUNT TYPE : VJ SETTLEMENT CURRENCY : USD TRADE DATE : 12-01- +15 VJRE 1917309 1 0234000876369 B 14-01-15 3,500,000.000 + 8,771,931.30- 0.200000- 185.58- PECT
        Output format is like below
        Line1: VSIN .... (Space) SETTLEMENT CURRENCY .... Line2: VJRE ... Line3: VJRE ... Line4: VSIN .... (Space) SETTLEMENT CURRENCY .... Line5: VJRE .... Line6: VJRE .... Line7: VJRE... Line8: VSIN. ...(Space) SETTLEMENT CURRENCY....