![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|
||||
|
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
|
||||
| Google UNIX.COM |