0

I need to count Nodes_Util for each Queue. In the example below, queue1 has only one line, but it varies and it could be nothing sometimes and it applies to all queues.

I want to dynamically add the number in the column if it exists.

Queue    | JOB_ID     | Tasks      | ptile      | Nodes_Util
queue1   | 220412     | 317        | 8          | 39
queue2   | 183623     | 317        | 16         | 19
queue2   | 220297     | 192        | 8          | 24
queue2   | 220298     | 192        | 8          | 24
queue2   | 220299     | 192        | 8          | 24
queue2   | 220300     | 192        | 8          | 24
queue2   | 220301     | 192        | 8          | 24
queue2   | 220302     | 192        | 8          | 24
queue2   | 220303     | 192        | 8          | 24
queue2   | 220304     | 192        | 8          | 24
queue2   | 220305     | 192        | 8          | 24
queue3   | 214071     | 187        | 16         | 11
queue3   | 214706     | 173        | 16         | 10
queue3   | 219981     | 128        | 16         | 8
queue3   | 220352     | 512        | 16         | 32
queue4   | 218227     | 576        | 16         | 36
queue4   | 220371     | 192        |            | 12
queue5   | 218106     | 256        | 16         | 16
queue5   | 220138     | 32         | 8          | 4
queue5   | 220382     | 16         | 8          | 2
queue5   | 220396     | 16         | 16         | 1
queue5   | 220403     | 16         | 16         | 1
queue5   | 220427     | 16         | 16         | 1
queue5   | 220566     | 32         | 8          | 4
queue6   | 219249     | 256        | 16         | 16
queue6   | 219267     | 256        | 16         | 16
queue6   | 220001     | 256        | 16         | 16

I need to know number of nodes utilized by each queue.

  • I think your question is unclear, could you provide desired example output, I assume this is input or give some more explanations. – taliezin Apr 23 '15 at 10:05
  • Yes, this is this input. We want to find which queue[column: Queue] is using how many nodes [column: Nodes_Util] – user3742796 Apr 23 '15 at 10:14
  • from the above given input "queue2" is using 235 nodes i.e by adding all the lines which starts with "queue2" – user3742796 Apr 23 '15 at 10:16
  • from the above given input, i want o/p as below queue1=39 queue2=235 queue3=61 queue4=48 queue5=29 queue6=48 – user3742796 Apr 23 '15 at 10:22
1

Something like this will work

awk -F" *| *" 'NR>1{a[$1]+=$NF}END{for(i in a)print i,a[i]}' file

Output

queue3 61
queue4 48
queue5 29
queue6 48
queue1 39
queue2 235

or if they are in order like your example

awk -F" *| *" 'NR==1{next}t!=$1{print t,x;x=""}{x+=$NF;t=$1}END{print t,x}' file

Output

queue1 39
queue2 235
queue3 61
queue4 48
queue5 29
queue6 48

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.