about awk

Archives
key_ruby

about awk

Postby key_ruby » Mon Feb 13, 2006 1:58 pm

question : analysis the file

Input file
+++++++++++++++++++++++++++++++++++++++++++++++++
mv_b1,mv_a1,rv_b1,rv_a1,rrv_b1,rrv_a1
mv_b2,mv_a2,rv_b2,rv_a2,rrv_b2,rrv_a2
mv_b3,mv_a3,rv_b3,rv_a3,rrv_b3,rrv_a3
+++++++++++++++++++++++++++++++++++++++++++++++++

Result:
when arrayname="detail",column="1" were specified
detail_1=mv_b1
detail_2=mv_b2
detail_3=mv_b3
when arrayname="keke",column="2" were specified
keke_1=mv_a1
keke_2=mv_a1
keke_3=mv_a1

I want to get the variables which names are named by index and arrayname. And the values are the corresbonding value of the specified column .
Arrayname and column are variable.

I have writed the code about this.
But I 'm not master of the awk
Any mistakes in the follow codes?

############################################
name="detail"
column="1"

var=`awk 'BEGIN{count=1}{ FS=","; print avar"_"count"="$column;count += 1}END{print avar"_size="count} ' avar="$name" column="$column" inputfile_ld`

eval "${var}"

#################################################

# My English is so.........
# Wish you will understand what I mean and help me .....
#Thank you .......

Return to “Archives”

Who is online

Users browsing this forum: No registered users and 2 guests