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!

Loading an array with the first field in a multi line file

Status
Not open for further replies.

jping45

Technical User
Aug 22, 2001
49
US
Hi all - -

I want to load an array, to be used later for a system command, with the first field in a multi-line file. The input file will have anywhere from 2 to 150 lines, give or take a few lines...

EX:

aaa 111 222 333
bbb 123 123 123
ccc 345 345 345
.
.

and have the value of the array be: aaa bbb ccc

any help would be great...
 
Another question for you..
how can I get the value of each element in the array printed on a single line?
 
Here's what I have so far...

awk '{a[NR]=$1}END{print a[NR]}' INPUTFILE

But this only prints the last element...

which in the above example would be "ccc"
 
Why an array ?
A starting point
Code:
awk '{printf "%s ",$1}' INPUTFILE

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
that's exactally what I've been looking for!!! thanks for the assistance...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top