The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cons: Configuration is done by editing the text-based config file ... - Techworld.com iBot UNIX and Linux RSS News 0 10-09-2007 06:10 AM
Extracting Data from a File oop UNIX for Dummies Questions & Answers 0 07-31-2007 08:48 AM
Extracting Data from xml file nishana Shell Programming and Scripting 3 07-13-2007 04:17 AM
how to insert data in database based on text file? forevercalz Shell Programming and Scripting 9 12-20-2005 07:40 PM
getting data from config file esham Shell Programming and Scripting 7 11-20-2005 08:24 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-09-2007
Registered User
 

Join Date: May 2007
Posts: 13
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

Last edited by zazzybob; 08-09-2007 at 04:30 AM. Reason: Disabled smilies
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-09-2007
Klashxx's Avatar
HP-UX/Linux/Oracle
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 371
Check this:

Code:
>cat maindatafile.dat 
9899000000,SMS
989901,DATA
9899000001,DATA
9899001000,SMS
9899001001,DATA
Code:
>cat myfile.confg 
9899000000,9899999999,DATA,b.dat
9899000000,9899999999,SMS,a.dat
Code:
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
Reply With Quote
  #3 (permalink)  
Old 08-09-2007
Registered User
 

Join Date: May 2007
Posts: 13
Extracting data from text file based on configuration set in config file

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
Reply With Quote
  #4 (permalink)  
Old 08-09-2007
Klashxx's Avatar
HP-UX/Linux/Oracle
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 371
Just a slight modification:
[quote=Klashxx;302131105]Check this:

Code:
>cat maindatafile.dat 
9899000000,SMS
989901,DATA
9899000001,DATA
9899001000,SMS
9899001001,DATA
Code:
>cat myfile.confg 
9899000000,9899999999,DATA,b.dat
9899000000,9899999999,SMS,a.dat
Code:
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
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0