Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, my file,calculate.txt is like this: Delay 5.60 PDR: 100.00 Sends: 440.00 Recv: 440.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0 Delay 5.59 PDR: 100.00 Sends: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    yat
    yat is offline
    Just Joined!
    Join Date
    May 2011
    Posts
    8

    Calculating average for all columns and convert into single file


    Hi, my file,calculate.txt is like this:

    Delay 5.60 PDR: 100.00 Sends: 440.00 Recv: 440.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.59 PDR: 100.00 Sends: 440.00 Recv: 440.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.62 PDR: 100.00 Sends: 440.00 Recv: 440.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.55 PDR: 99.09 Sends: 440.00 Recv: 436.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.61 PDR: 98.86 Sends: 440.00 Recv: 435.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.59 PDR: 99.55 Sends: 440.00 Recv: 438.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.61 PDR: 98.86 Sends: 440.00 Recv: 435.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.64 PDR: 97.95 Sends: 440.00 Recv: 431.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.62 PDR: 98.86 Sends: 440.00 Recv: 435.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.58 PDR: 99.77 Sends: 440.00 Recv: 439.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    Delay 5.60 PDR: 99.77 Sends: 440.00 Recv: 439.00 bundles sent = 0 bundles recv= 0 Bundles dropped : 0

    i want to calculate the average of all value (delay PDR etc) and it will become single file like this one (value is just example):

    delay: 5.5
    PDR: 99
    bundles sent: 3
    .
    .
    .

    any hel;ps appreciated

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    238
    hi,

    awk is the tool you should use.

    I'd re-format each line to replace anything that is not a number or a part of it by a Field_Separator, do the sum of each field, and, at the END, do the average, and format the output.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •