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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in multiple lines into seperate variables

Status
Not open for further replies.

jpor

Technical User
Nov 29, 2000
212
GB
Hi again,

Currently devising a way to read in 1 line at a time from a text file but each line needs to be stored in a seperate variable. I have used this sort of code before to store a line at a time into 1 variable:

while read

do

set $id
## num=${4#"("}
## num=${num%")"}
id2=$1

sacego /usr/cs3/ace/rtmdesper2 "$J1" "$J2" "$J3" "$J4" "$J5" "$J6" "$J7" "$J8"

sleep 3

done < /tmp/ericentry

What I want to do is pipe the variables J1 - J8 to the ace report.

Any ideas ?

Thanks again in advance.
 
For example from the file ericentry:

I have numbers such as:

1234
4321
5678
8765
7890
0987
2468
8642

So when the while read line script runs I need it to do this:

variable J1 = 1234
variable J2 = 4321
variable J3 = 5678
variable J4 = 8765
variable J5 = 7890

And so on...

I need seperate variables rather than an array due to using these seperate variables to pipe into an Informix Ace report.

Any help appreciated. As it is now doing my head in.

Thanks again in advance.
 
#!/bin/ksh

file='/tmp/ericentry'
args=&quot;$(tr '\n' ' ' < ${file})&quot;

eval sacego /usr/cs3/ace/rtmdesper2 &quot;${args}&quot;

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vgersh99 Thanks for the reply.

Although this is off key to Unix Shell scripting. When I get the &quot;${args}&quot; into the ace report, how will I be able to define the variable ? The way I was hoping to do it is with the seperate &quot;$J1&quot; &quot;$J2&quot; etc... And within the Ace report define this as:

param[1] J1 char(8)
param[2] J2 char(8)

And then use the these to run a database select with sql reporting. The J variables will need to be defined as seperate due to how I will be using the select against the Informix database table and indiviudally picking out seperate Job Numbers, for example:

select js_job_no
from jobsheet

where js_job_no in ( &quot;$J1&quot;, &quot;$J2&quot;, &quot;$J3&quot; etc...



I am not sure how I will be able to accomplish this with the method you are giving me.


 
If you insist to have exported Jx variables in your shell script, you can try something like this(in ksh):
Code:
eval $(awk '{printf &quot;export J%d=%s\n&quot;,NR,$1}' /tmp/ericentry)

Hope This Help
PH.
 
Thanks PHV. I will give it a try. I am not being un-greatful when it comes to the array help. But as the saying goes. &quot;If it ain't broke.... Don't fix it&quot;.

 
PHV. That works. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top