Wednesday, 23 November 2011

concatenate 2 variables in dialog using awk while in for loop

concatenate 2 variables in dialog using awk while in for loop

Hi,

I have a variable $accessgroups, which has a series of comma-delimited values, like:

group_a,group_b

The other variable $restaccessgroups has:

group_f,group_g

I also have another set of variables:

group_a_descr=Description of group a
group_b_descr=Description of group b
group_f_descr=Description of group f
group_g_descr=Description of group g


I now want a dialog with group_a and the value of $group_a_descr

Code:

dialog --separate-output --output-separator "," --checklist blah 20 80 10 `echo $accessgroups | awk -F, '{ for (i = 1; i < NF; ++i ) print $i " " ${i}_descr " on"}'` `echo $restaccessgroups | awk -F, '{ for (i = 1; i < NF; ++i ) print $i " " ${i}_descr " off"}'`
This gives me

Code:

(*)  group_a    group_a,group_b
(*)  group_b    group_a,group_b
( )  group_f    group_f,group_g
( )  group_g    group_f,group_g

What I want:

Code:

(*)  group_a    Description of group_a
(*)  group_b    Description of group_b
( )  group_f    Description of group_f
( )  group_g    Description of group_g

I have tried:

awk -F, '{ for (i = 1; i < NF; ++i ) print $i " " $i_descr " on"}'
awk -F, '{ for (i = 1; i < NF; ++i ) print $i " " ${$i}_descr " on"}'
awk -F, '{ for (i = 1; i < NF; ++i ) print $i " ${i}_descr" " on"}'

with no success.

I am open to alternatives to awk.... :)

No comments:

Post a Comment