Page 1 of 1

Unstring a record using REXX

Posted: Thu Apr 18, 2013 8:32 pm
by Vishwanath G N
Hi All,

I have a file with records in below format.
6,"1","",45,4567,"","QW3454","23244","23424",23423',


I want to read 5th and 8th value from all the records. Ie 4567 and 23244 and write these two values in a new file.


Can someone please guide me on how this can be done using REXX.

Posted: Thu Apr 18, 2013 9:02 pm
by MrSpock
Use a PARSE VAR statement to parse the record into individual tokens. Then you can use the 5th and 8th tokens in your output process.

Posted: Thu Apr 18, 2013 11:22 pm
by Vishwanath G N
I am able to get 8th value but it is coming with " ie "24244"
I am unable to remove " in parse itself.

Posted: Thu Apr 18, 2013 11:34 pm
by DikDude
I am able to get 8th value but it is coming with " ie "24244"
A typo or a different record being parseed?

Suggest you post the code (using the "Code" tag" to preserve alignment and improve readability).

Posted: Fri Apr 19, 2013 1:59 am
by MrSpock
Well, theoretically, you could PARSE them all out:

Code: Select all

Parse Var v tok1 ',"' tok2 '",' '"' tok3 '",' tok4 ',' ,        
  tok5 ',"' tok6 '","' tok7 '","' tok8 '","' tok9 '",' tok10 "'" .
but I think it would be easier to just use STRIP to remove them afterward, i.e.

Code: Select all

tok8 = Strip(tok8,B,'"')