1

im working on sun10 Solaris os,i have a process that returns table as by using this command dmh -q 12 the below:

*PROFILE   PRIORITY   COMM_TYPE     QID    # OF MSGS   ATTRIBUTES/VALUES*
      13        999          DC      24            3     32  1865
      13        999          DC      94            1     32  1665
      13        999          DC     157            0     32  1961
      13        999          DC     188            2     32  1784
      13        999          DC     293            0     32  1625
      13        999          DC     294           31     32  1950
      13        999          DC     713            0     32  1601
      13        999          DC     838            0     32  1607
      13        999          DC    1458            0     32  1855

here im trying to get the total count of messages and store it in the variable I have tried this but it doesn't work with me:

dmh -q 12 | grep -v'# OF MSGS' | wc -l 

the expected result should be 37

3

Using awk:

dmh -q 12 | awk 'NR > 1 { sum += $5 } END {print sum}'

This will sum all the values in column 5 and then print the total.

To store this in a variable use command substitution:

var=$(dmh -q 12 | awk 'NR > 1 { sum += $5 } END {print sum}')
1

Based on the input provided, you could use the dc utility:

$ dmh -q 12 | sed -e '1d;y/-/_/' | dc -e "[lMpq]sq [s0s0lM+sM]sm [?z0=qlmxcz0=?]s? 0sMl?x"
37

Note: This is assuming that you have a total of 7 columns in a row.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.