Page 1 of 1

Replace a pattern in a record in dynamic position.

PostPosted: Thu Nov 13, 2014 9:50 pm
by DebaMF
I have a file with multiple records where a specific phrase/pattern need to find out replace with another set of specific text. Position of specific phrase/pattern in a record is not fixed. The file length is 50 bytes.

Input File:

MAINAK INCOME ANNUL AT RS 1000
JOHN INCOME MONTH AT RS 1340
MAXICANA INCOME DAILY AT RS 1568


The specific phrase/pattern is 'INCOME %%%%% AT RS', where '%%%%%' is variable but it will be always 5 bytes. Need to replace 'INCOME %%%%% AT RS' with 'INCOME DETAILS'.
In another way, wherever 'AT RS' is found, need to replace: the minus 6 bytes of 'AT RS' plus 'AT RS' with 'DETAILS'.

Output File:

MAINAK INCOME DETAILS 1000
JOHN INCOME DETAILS 1340
MAXICANA INCOME DETAILS 1568



It will be great help if anyone can please help me to build the SORT card (SYNCSORT) to achive this.

coded

Re: Replace a pattern in a record in dynamic position.

PostPosted: Fri Nov 14, 2014 11:31 am
by DebaMF
Sorry, its my mistake. It should be 'ANNUL'

Corrected in original

Re: Replace a pattern in a record in dynamic position.

PostPosted: Fri Nov 14, 2014 6:09 pm
by BillyBoyo
PARSE. You need one PARSE field which finishes before "balnkINCOMEblank", with a fixed length of the logical maximum of that data. Second PARSE field just gets the next 18 bytes, then third gets the maximum logical length of that data.

The second PARSE field I'd check to see it has "blankATblankRSblank" if there is any possibility that the search string could appear in the data.

Then you put together the output you want, first PARSE field, litera, third PARSE field and SQZ the result. If you need multiple consecutive blanks in your output, you'll have a little more work as well.