Reading a .dat file in to 2 different arrays

hi all, i have a data file that contains 2 columns, names and numbers. i need to read names in to a an array call names and numbers in to an array call numbers. i also have # and blank lines in my dat file and i need to skip those when i read the dat file. how do i do this? btw, my column 1 and column 2 is seperated by "TAB". i am using k shell (.ksh).

i was able to read without an issue when there was a one cloumn of data. i am not sure how to do this with 2 columns. can someone please help me?

Data file format as follows

2345th3 rghtyk
2345thh fhtene

345672 dkerjgt
#fjerflghh
er4566 djefklrgl

i would like arrays to be like this,
numbers[0]=2345th3
numbers[1]=2345thh
numbers[2]=345672
numbers[3]=er4566

names[0]=rghtyk
names[1]=fhtene
names[2]=dkerjgt
names[3]=djefklrgl

assuming I got what you want - try this (requires a modern awk, on
solaris try nawk):

awk '{ if( /^#/ || /^$/ ) {next}
         print $1 >> "one"; 
         print $2 >> "two"   
      }' inputfile

The file named one has column one
the file named two has column two
/^$/ == blank line
/^#/ == line starting with a #

Try...

$ eval $(awk '!/^$/&&!/^#/{printf "numbers[%s]=%s\nnames[%s]=%s\n",c+0,$1,c++,$2}' file1)

$ echo ${names[2]}
dkerjgt

$ echo ${numbers[3]}
er4566

$

Thank you very much, both of you guys. :slight_smile: