View previous topic :: View next topic
|
Author |
Message |
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Hi All ,
Is there any way to read character delimited files in REXX.(i.e reading @ delimited files or $ delimited files.
Rexx understands space delimited words so we can split the data with WORD function , but
is REXX capable of splitting words delimited by other characters, say '@' or $ with any functions and without the brute force method.
Our forum with the search string as 'delimit' gives this link ,
ibmmainframes.com/viewtopic.php?t=34762&highlight=delimit
I tried the TSO-E/REXX manual and it says only about blank delimiters and " delimiters.
WORD
WORD(string,n)
returns the nth blank-delimited word in string or returns the null string if fewer than
n words are in string. The n must be a positive whole number. This function is
exactly equivalent to SUBWORD(string,n,1).
Here are some examples:
WORD('Now is the time',3) -> 'the'
WORD('Now is the time',5) -> ''
The file that needs to be read has the following structure, and it is not column delimited
51847@00000001@51041220@041220@1@0000000@
Could you please show some light in the tunnel? |
|
Back to top |
|
|
PeD
Active User
Joined: 26 Nov 2005 Posts: 459 Location: Belgium
|
|
|
|
If there are no blanks anywhere in the record, translate @ to blank,
then process by word. |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Hi PeD,
Thanks for your time,
But unfortunately there are blanks in the input file
Thanks in advance, |
|
Back to top |
|
|
PeD
Active User
Joined: 26 Nov 2005 Posts: 459 Location: Belgium
|
|
|
|
In this case, you will have to play INDEX or POS in a loop.
If I had to do that, my approach will be that one. |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Omg That looks like mammoth task...
I wish there was a simple function like "WORD"
Also there are 100's of variables so was unable to use the below example,
"EXECIO 1 DISKR indd"
PARSE PULL record
PARSE VAR record fld1 ',' fld2 ',' fld3 ',' fld4 ',' ... |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
Code: |
string = "abcd$efg$hi h$ k $s eee$eeer"
parse var string t1 "$" t2 "$" t3 "$" t4 "$" t5 "$" t6 "$" t7 "$" tail
say "t1 >"t1"<"
say "t2 >"t2"<"
say "t3 >"t3"<"
say "t4 >"t4"<"
say "t5 >"t5"<"
say "t6 >"t6"<"
say "t7 >"t7"<"
say "tail>"tail"<"
|
|
|
Back to top |
|
|
genesis786
Active User
Joined: 28 Sep 2005 Posts: 210 Location: St Katherine's Dock London
|
|
|
|
hi,
i tried something like this. not sure if it fits ur requirement:
Code: |
rec = '51847@00000001@51041 220@041 220@1@000 0000@'
tmprec = rec
i = 1
do while tmprec <> ''
parse value tmprec with tmpwrd '@' extra
tmprec = extra
say 'Word' i '=' tmpwrd
say extra
i = i + 1
end
|
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
follow on
Code: |
string = "51847@00000001@51041220@041220@1@0000000@"
parse var string t1 "@" t2 "@" t3 "@" t4 "@" t5 "@" t6 "@" t7 "@" tail
say "t1 >"t1"<"
say "t2 >"t2"<"
say "t3 >"t3"<"
say "t4 >"t4"<"
say "t5 >"t5"<"
say "t6 >"t6"<"
say "t7 >"t7"<"
say "tail>"tail"<"
|
result
Code: |
enrico-pBook:~ enrico$ ./test.rx
t1 >51847<
t2 >00000001<
t3 >51041220<
t4 >041220<
t5 >1<
t6 >0000000<
t7 ><
tail><
enrico-pBook:~ enrico$
|
|
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Hi genesis786,
Thanks for the code, I works like a charm
Exactly what I needed.
Enrico,
Thanks to you too for providing a super simple method..
Im gona celebrate this... |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
Quote: |
Thanks to you too for providing a super simple method.. |
I did not provide anything... REXX did it
and how to exchange the value of two variables in one shot ???
( only limitations is no blanks in the variable content )
Code: |
a = "xxxx"
q = "zzzz"
say "a >"a"<"
say "q >"q"<"
parse value a q with q a
say "a >"a"<"
say "q >"q"<"
|
|
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
This looks like the Tumblers and ball magic trick....
nice |
|
Back to top |
|
|
|