Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the REXX Parse command with a text delimited file

Status
Not open for further replies.

gmeikle

Technical User
Nov 6, 2013
10
GB
Good morning all,

After years of using the ProComm app for building scripts I have finally moved across to Zoc Terminal due to the need to use SSH connection.

I have only started to play with the scripts but have hit a problem using text delimited files and thought I would fire my question out into the big wide world to try to get a quick answer.

I have built the following test script to display the different variables but when it comes down to displaying the name it separates this into the different words, i.e. it takes the spaces as delimiters.

Any help would be much appreciated.

Script:
/* REXX */
file = "c:\Names.txt"
IF STREAM(file, "C", "QUERY EXISTS")\="" THEN SAY "File Exists"
do while( lines(file) )
data=LINEIN(file)
Parse Var data v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12
say v1
say v2
say v3
say v4
say v5
say v6
say v7
say v8
say v9
say v10
say v11
say v12
END

File:
1111 Test Name 1 40 5 10 20 30 40 50 60 120 180
2222 Test Name 2 40 5 10 20 30 40 50 60 120 180

When I run this the different variables shows as follows:
v1 - 1111
v2 - Test
v3 - Name
v4 - 1
v5 - 40
v6 - 5
v7 - 10
v8 - 20
v9 - 30
v10 - 40
v11 - 50
v12 - 60 120 180
v1 - 2222
v2 - Test
v3 - Name
v4 - 2
v5 - 40
v6 - 5
v7 - 10
v8 - 20
v9 - 30
v10 - 40
v11 - 50
v12 - 60 120 180
 
What do you mean by "text delimited"?

PARSE breaks your input at spaces because you specify spaces: v1 v2 v3 etc
If you wanted to break at commas then you would use v1 ',' v2 ',' v3 etc
You can also parse by column position and by values stored in variables.


Nic
 
Hi Nic,

Thank you for your reply about difference between delimiters.

So, reading through your reply can I assume that I cannot delimit by tabs?

Glen.
 
A tab is just a hex character - stick that hex code into a variable and it should work.


Nic
 
Hi Nic & papadba,

Thank you for your replies.

Please excuse my ignorance as I am new to REXX coding but I am not sure by what you mean when you say "stick the hex code into a variable and it should work"?

What would i need to program within my original script?

Glen.

 
gmeikle said:
When I run this the different variables shows as follows:
v1 - 1111
v2 - Test
v3 - Name
v4 - 1
v5 - 40
v6 - 5
v7 - 10
v8 - 20
v9 - 30
v10 - 40
v11 - 50
v12 - 60 120 180
v1 - 2222
v2 - Test
v3 - Name
v4 - 2
v5 - 40
v6 - 5
v7 - 10
v8 - 20
v9 - 30
v10 - 40
v11 - 50
v12 - 60 120 180

But could you say please what you wish to have instead of this output?
 
Are you using ASCII or EBCDIC because in ASCII the tab character is x'09' - just assign that to a variable.


Nic
 
Good morning all and thank you for all of your replies.

This table shows the output of an Excel Tab Delimited file which contains the information I wish to display and where the Vx is the heading of each column within the Excel Tab Delimited file.
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12
1111 Test Name 1 40 5 10 20 30 40 50 60 120 180
2222 Test Name 2 40 5 10 20 30 40 50 60 120 180

I am looking to build a script that will identify each of the fields within the tab delimited files and to display the output as the name in full, i.e. the rhs column not the lhs column

V1 1111 V1 1111
V2 Test V2 Test Name 1
V3 Name V3 40
V4 1 V4 5
V5 40 V5 10
V6 5 V6 20
V7 10 V7 30
V8 20 V8 40
V9 30 V9 50
V10 40 V10 60
V11 50 V11 1200
V12 60 120 180 V12 180
V1 2222 V1 2222
V2 Test V2 Test Name 2
V3 Name V3 40
V4 2 V4 5
V5 40 V5 10
V6 5 V6 20
V7 10 V7 30
V8 20 V8 40
V9 30 V9 50
V10 40 V10 60
V11 50 V11 1200
V12 60 120 180 V12 180

I hope this helps?
 
Difficult to say as I do not see how your output relates to your input when parsed using tabs.

Say column headings are ch1 through ch12 and data cells are variables r1 through r12 then parsing the column headings with tabs would give you:
ch1 = v1; ch2 = v2 etc
and parsing the data rows would give, for the first data row:
r1 = 1111; r2 = Test Name 1; r3 = 40 etc
assuming that the tabs are after 1111, "Test Name 1", 40 etc

tabchar = '09'x
parse var excel_row v1 (tabchar) v2 (tabchar) v3 .......etc


Nic
 
Hi Nic,

Thank you, that has worked perfectly.

I was nearly there from the information in the thread but what was throwing me was that the tab values shown had the x at the front and not at the back, i.e. x'09' and not '09'x.

Once again, thank you to all of the follow members who replied back to me.

Kind regards,
Glen
 
When the individual columns contain values with spaces then tab would be a little bit unhappy chosen delimiter. It is better to choose e.g. semicolon.

If you wish to name all your variables so simple like Vj (j=1,2,..) you can do it much more elegant using stem V.j in a loop. Nice example is given here:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top