BeginDate 07/01/06
End: 07/31/06
Cust: A02991 - Burnham
0002000 5,829,773 145.3
0009701 4,043,850 267.3
2005000 286,785.13 100.0
BeginDate 07/01/06
End: 07/31/06
Cust: A01239 - East Track PSE
Index A
0009902 317,356.82 890.2
0020021 94,694.23 90989.1
BeginDate 07/01/06
End: 07/31/06
Cust: A04067 - Fidelity Growth
investement
0009902 1,063,852 2990.3
0020021 699,709.35 4590.3
Above is my incoming file format.
I need to create a file with 6 columns( BeginDate,EndDate,Cust and the three associated columns with each Customer).The customer record
some times may be shown as 2 records.I need to make as one record.
I am kind of lost how to solve
anbu23
September 27, 2006, 5:22pm
2
can you show us the output you needed?
Begin End Cust: Col1 Col2 Col3
07/01/06 07/31/06 A02991 - Burnham 0002000 5,829,773 145.3
07/01/06 07/31/06 A02991 - Burnham 0009701 4,043,850 267.3
07/01/06 07/31/06 A02991 - Burnham 2005000 286,785.13 100.0
This is how i need the output.
anbu23
September 27, 2006, 6:05pm
4
awk '
/BeginDate/ {
getline end_dt
getline cust
getline cust1
sub(".* ","",$0)
bgn_dt=$0
sub(".*: ","",end_dt)
sub(".*: ","",cust)
if ( match ( cust1 , "^[0-9][0-9]*" ) )
print $0 " " end_dt " " cust " " cust1
else
{
cust = cust cust1
}
}
/^[0-9]+/{
print bgn_dt " " end_dt " " cust " " $0 }' file
here's a slightly different approach:
nawk -f kris.awk myFile.txt
kris.awk:
BEGIN {
FS=RS=""
}
{
head=sprintf("%s%s", substr($1, index($1, " ")+1), OFS)
head=head sprintf("%s%s", substr($2, index($2, " ")+1), OFS)
head=head sprintf("%s%s", substr($3, index($3, " ")+1), OFS)
for(f=4; f<=NF; f++)
if( $f ~ /^[0-9]/ )
printf("%s%s\n", head, $f)
}