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

creating an array from stdin

Status
Not open for further replies.

marsd

IS-IT--Management
Apr 25, 2001
2,218
US
Problem looks like this:

awk ' BEGIN {
getline c < &quot;-&quot;
getline b < &quot;-&quot;
getline e < &quot;-&quot;

I would really love to be able to do something like this:
my_arr[x,y,z] = c b e
but I don't think this can be done.
so I settle for something like this:
name[1] = c
name[2] = b
name[3] = e

when I loop through them:
for (x in name) {
print name[x]
}
I get a random single element.
Could somebody explain this behavior to me
and how I can avoid it?
gawk version 3.0.98

Thanks for any help.
 
Hi,

try this :

name[1] = &quot;a&quot;;
name[2]= &quot;b&quot;;
name[3] = &quot;c&quot;;
for (x=1;x<4;x++)
print name[x]

Regards.

Fcail
 
Thanks fcail.

I fixed it by doing this kludge:
getline a < &quot;-&quot;
getline b < &quot;-&quot;
getline c < &quot;-&quot;
full = a&quot;:&quot;b&quot;:&quot;c&quot;:&quot;
split(full,arr,&quot;:&quot;)
for (info in arr) {
print arr[info]
}
And writing it as a function; I'll try your way and see if it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top