Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with processing a data file.... 1

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I have created a data file and would like to pull specific info out..

Here's how the file looks like

#----------------- cut here -----------------#
mm/dd/yyyy
<blank_line>
amount
client1 data_amount
client2 data_amount
client3 data_amount
client4 data_amount
client5 data_amount
client6 data_amount
<blank_line>
speed
client1 data data data speed kb/s data
client2 data data data speed kb/s data
client3 data data data speed kb/s data
client4 data data data speed kb/s data
client5 data data data speed kb/s data
client6 data data data speed kb/s data
<blank_line>
mm/dd/yyyy
<blank_line>
amount
client1 data_amount
client2 data_amount
client3 data_amount
client4 data_amount
client5 data_amount
client6 data_amount
<blank_line>
speed
client1 data data data speed kb/s data
client2 data data data speed kb/s data
client3 data data data speed kb/s data
client4 data data data speed kb/s data
client5 data data data speed kb/s data
client6 data data data speed kb/s data
<blank_line>
mm/dd/yyyy
<blank_line>
amount
client data_amount
client data_amount
client data_amount
client data_amount
client data_amount
client data_amount
<blank_line>
speed
client data data data speed kb/s data
client data data data speed kb/s data
client data data data speed kb/s data
client data data data speed kb/s data
client data data data speed kb/s data
client data data data speed kb/s data
<blank_line>
#----------------- cut here -----------------#

There would be up to two weeks of data in the file. Each days data is seperated with "mm/dd/yyyy"

I would like to generate 2 reports that looks like:

ClientX mm/dd/yyyy mm/dd/yyyy mm/dd/yyyy mm/dd/yyyy
client1 data_amount data_amount data_amount data_amount
client2 data_amount data_amount data_amount data_amount
client3 data_amount data_amount data_amount data_amount
client4 data_amount data_amount data_amount data_amount
client5 data_amount data_amount data_amount data_amount
client6 data_amount data_amount data_amount data_amount

ClientX mm/dd/yyyy mm/dd/yyyy mm/dd/yyyy mm/dd/yyyy
client1 speed speed speed speed
client2 speed speed speed speed
client3 speed speed speed speed
client4 speed speed speed speed
client5 speed speed speed speed
client6 speed speed speed speed

data_amount = a number representing amount of data backed up
speed = a number representing speed in kb/s

how would I do this with awk?

Thanks......

Joe Despres
 
Here's what I have so far:

1:: Pull out the dates.....

grep "../../...." file_with_the_data.txt|awk '{printf "%s,",$0;getline;printf "%s,",$0;getline;printf "%s,",$0}'

2:: Pull out the amount info.....

awk '/amount/,/^$/ {print $2, $3}' file_with_the_data.txt

3:: Pull out the speed info....

awk '/speed/,/^$/ {print $4}' file_with_the_data.txt

I need to be able to line up the data.....

probably need to stick a coma in there as a delimiter..

Joe Despres
 
Try this:

Code:
awk '
        /^$/ { next }
        /^..\/..\/....$/ { date=$0; dates[++dateix]=date; next }
        $1 == "amount" { amount=1; speed=0; next }
        $1 == "speed"  { amount=0; speed=1; next }
        amount { amounts[$1,date]=$2 }
        speed  { speeds[$1,date]=$5 }
        !($1 in clients) { clients[$1] }
        END {
                printf "%-20s","client"
                for (d=1; d<=dateix; d++) {
                        printf "%-20s",dates[d]
                }
                printf "\n\namounts\n"
                for (c in clients) {
                        printf "%-20s",c
                        for (d=1; d<=dateix; d++)
                                printf "%-20s",amounts[c,dates[d]]
                        printf "\n"
                }

                printf "\n\nspeeds\n"
                for (c in clients) {
                        printf "%-20s",c
                        for (d=1; d<=dateix; d++)
                                printf "%-20s",speeds[c,dates[d]]
                        printf "\n"
                }
        }
' inputfile

Annihilannic.
 
wow...... that is very good.....

All I need now is to include GB or MB for amount for each one and it's done!

Thanks!

Joe Despres
 
Here's a example of amount data:

1994.02 GB
1724.31 GB
1519.89 GB
261.78 GB
998.18 GB
2566.70 GB
564.23 GB
704.21 GB
96.83 GB
4393.65 GB
432.33 GB
1077.48 GB
17.59 GB
446.26 GB
14.83 GB
1.93 GB
623.50 MB
20.09 GB
775.88 MB
159.03 MB
1128.62 GB


Thanks...

Joe Despres
 
Oh yeah...............

It seems to be missing a days worth of data....

Thanks....

Joe Despres
 
for some reason or another it's missing the 3rd set of data....

Joe Despres
 
Without seeing your actual input data it's difficult to guess why it's not working for you.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top