awkformatgawkiostatmegabyte

ioStat and Awk Output and Format with Megabyte and end of each field


Would it be possible to add a "Mb" to the end of just MB_r/s and MB_wn/s. Awk is getting 3 fields and reporting them during the test line to line like below:

example: Format output below:

                            ^        ^              
90,    11 Kb,      12 Kb,    101253,    1.45,    1890.77,    427911.58
74,    11 Kb,      12 Kb,    101253,    1.45,    1890.77,    427911.58
89,    11 Kb,      12 Kb,    101253,    1.45,    1890.77,    427911.58

Command being used I need to have Mb on last 2 reported from awk.

iostat -m 3 2 |  grep dm-0 |awk '{a+=$2;b+=$3;c+=$4}END {print a"\n"b"\n"c"\n"}'

I want it to read like below example:

                                            ^          ^          
90,    11 Kb,      12 Kb,    101253,   1.45Mb,   1890.77Mb,    427911.58
74,    11 Kb,      12 Kb,    101253,   1.45Mb,   1890.77Mb,    427911.58
89,    11 Kb,      12 Kb,    101253,   1.45Mb,   1890.77Mb,    427911.58


Solution

  • I actually found out how:

    iostat -m 3 2 | grep dm-0 |awk '{a+=$2;b+=$3;c+=$4}END {print a"\n"b"Mb\n"c"Mb\n"}'
    

    Worked perfectly :-).