parsing config file to create new config files

Hi,

I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below.

I will be using the config file as mentioned below:
(config.txt)

country:a,b
city:1,2
type:b1
date:11-Dec-2009

I want to create config files as mentioned below:
(a_1.cfg)

country:a
city:1
type:b1
date:11-Dec-2009

(a_2.cfg)

country:a
city:2
type:b1
date:11-Dec-2009

(b_1.cfg)

country:b
 city:1
 type:b1
 date:11-Dec-2009

(b_2.cfg)

 country:b
  city:2
  type:b1
  date:11-Dec-2009

Any help is greatly appreciated!!!:slight_smile:

Thx

Clazzic

You may try something like this:

awk -F: '{ map[$1] = $2; idx[NR] = $1 }
NR == 3 {
  n  = split(map[idx[1]], t, c)
  nn = split(map[idx[2]], tt, c)
  for (i=0; ++i<=n;) 
    for (j=0; ++j<=nn;) { 
      print idx[1], t > (fn = t "_" tt[j] ".cfg")
      print idx[2], tt[j] > fn
      print > fn
    }
  next
  }
{ 
  for (i=0; ++i<=n;) 
    for (j=0; ++j<=nn;) 
      print  > (fn = t "_" tt[j] ".cfg") 
  }' OFS=: c=, infile