Extracting data from text file based on configuration set in config file

Hi ,

a:) i have configuration file with pattren
<Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output>

eg:

myfile.confg
9899000000,9899999999,DATA,b.dat
9899000000,9899999999,SMS,a.dat

b:) Stucture of my data file is :
<no>,<type of record>

eg
maindatafile.dat
9899000000,SMS
9899000001,DATA
989901,DATA

Now i want to extract the records from main file
Condition
One check is of range and other will be of Record type defined in configuration file

Output should be like :
File Name : >>>>> b.dat
9899000001,DATA

Similarly seperate files based on range and Record type should be created.

Can anybody help to get this achieved in best possible way...

Thanks in Advance

Check this:

>cat maindatafile.dat 
9899000000,SMS
989901,DATA
9899000001,DATA
9899001000,SMS
9899001001,DATA
>cat myfile.confg 
9899000000,9899999999,DATA,b.dat
9899000000,9899999999,SMS,a.dat
awk -F\, '
BEGIN {
FNR==NR} 
{
if ( NF == 2 )
   {
   i++
   ori[$2,i]=$1
   }
if ( NF == 4 )
   {
   ori[$3]
   if ($3 in ori)
      for(o=1;o<=i;o++)
         if ( ori[$3,o] > $1 && ori[$3,o] < $2 )
            printf("File Name :%s\n%s,%s\n",$4,ori[$3,o],$3)
   }
}' maindatafile.dat myfile.confg
File Name :b.dat
9899000001,DATA
File Name :b.dat
9899001001,DATA
File Name :a.dat
9899001000,SMS

Hi Klashxx ,

Thanx for the solution , but the output is not the way i wanted

output iam looking for is

a.dat file sohuld contain all records in the range defined for SMS record type

so
cat a.dat
9899000000,SMS
9899001000,SMS

Similarly

b.dat file sohuld contain all records in the range defined for DATA record type

cat b.dat
9899000001,DATA
9899001001,DATA

Just a slight modification:

[quote=klashxx;302131105]
Check this:

>cat maindatafile.dat 
9899000000,SMS
989901,DATA
9899000001,DATA
9899001000,SMS
9899001001,DATA
>cat myfile.confg 
9899000000,9899999999,DATA,b.dat
9899000000,9899999999,SMS,a.dat
awk -F\, '
BEGIN {
FNR==NR} 
{
if ( NF == 2 )
   {
   i++
   ori[$2,i]=$1
   }
if ( NF == 4 )
   {
   ori[$3]
   if ($3 in ori)
      for(o=1;o<=i;o++)
         if ( ori[$3,o] > $1 && ori[$3,o] < $2 )
               {
               if ( $3 == "SMS" )
                    print ori[$3,o]","$3>"a.dat"
               if ( $3 == "DATA" )
                   print ori[$3,o]","$3>"b.dat"
               }
   }
}' maindatafile.dat myfile.confg