View previous topic :: View next topic
|
Author |
Message |
Sebin89
New User
Joined: 14 Dec 2020 Posts: 10 Location: Germany
|
|
|
|
I have a VB file were can a HEX value ‘0D25’ come in any position from 1 to 20 (values from 21 position onwrd should not be changed). This need to be replaced with HEX value ‘4040’.
Input:
Code: |
----+----1----+----2----+----3----+----4----+
0000/12345678 566 @(#)@0000/12345678 566
FFFF6FFFFFFFF02FFF44B475BFFFF6FFFFFFFF02FFF02
0000112345678D5566005DBD50000112345678D5566D5
|
Expected output:
Code: |
----+----1----+----2----+----3----+----4----+
0000/12345678 566 @(#)@0000/12345678 566
FFFF6FFFFFFFF44FFF44B475BFFFF6FFFFFFFF02FFF02
000011234567800566005DBD50000112345678D5566D5
|
I was using SORT with below control card.
Code: |
SORT FIELDS=COPY
OUTREC FIELDS=(1,4,5,20,CHANGE=(20,X'0D25',X'4040'),
NOMATCH=(5,20),
21)
|
could you please help me to adjust the control card? |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1255 Location: Bamberg, Germany
|
|
|
|
Use FINDREP. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1255 Location: Bamberg, Germany
|
|
|
|
Code: |
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
FINDREP=(INOUT=(X'0D25',X'4040'),STARTPOS=5,ENDPOS=24,DO=99))
END |
|
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
FYI- CHANGE will only replace if something found at that position and hence it will not work here as it will not scan thru 5-20.
Code: |
DO=n
Specifies the maximum number of times find and replace is to be performed for a record,
overriding the default of every time. Scanning for the input constant stops when n input constants
have been found and replaced. Use DO=n if you want to stop after a particular number of
constants have been replaced. n can be 1 to 1000. |
|
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1255 Location: Bamberg, Germany
|
|
|
|
Rohit Umarjikar wrote: |
FYI- CHANGE will only replace if something found at that position and hence it will not work here as it will not scan thru 5-20. |
Obviously it does work.
Input:
Code: |
0000/12345678 566 @(#)@0000/12345678 566
FFFF6FFFFFFFF02FFF44B475BFFFF6FFFFFFFF02FFF02
0000112345678D5566005DBD50000112345678D5566D5 |
Output:
Code: |
0000/12345678 566 @(#)@0000/12345678 566
FFFF6FFFFFFFF44FFF44B475BFFFF6FFFFFFFF02FFF02
000011234567800566005DBD50000112345678D5566D5 |
|
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
If its a constant position to be scanned and replaced then simple IFTHEN with OVERLAY would do. FINDREP is needed to replace if it occurs between 5-20 anywhere, n times as that is the expectation from the original post. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2023 Location: USA
|
|
|
|
Rohit Umarjikar wrote: |
If its a constant position to be scanned and replaced then simple IFTHEN with OVERLAY would do. FINDREP is needed to replace if it occurs between 5-20 anywhere, n times as that is the expectation from the original post. |
DO= is in effect when there are more than one occurrence of required value to be changed.
DO=99 is specified to guarantee ANY possible number of occurrences between positions 5 and 25. E.g., "more than enough". |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
Saying the same thing over again. Let us close it out. |
|
Back to top |
|
|
Sebin89
New User
Joined: 14 Dec 2020 Posts: 10 Location: Germany
|
|
|
|
Many thanks for the suggestions. Slightly modified CNTL worked.
Code: |
OPTION COPY
OUTREC FINDREP=(INOUT=(X'0D25',X'4040'),STARTPOS=5,ENDPOS=24)
|
|
|
Back to top |
|
|
|