I have to filter the output of the command sar
, showing only the third to last column.
The output of the command is similar to this:
16:20:01 CPU %user %nice %system %iowait %steal %idle
16:30:01 all 0,00 0,00 0,01 0,00 0,00 99,99
16:40:01 all 0,00 0,00 0,00 0,00 0,00 100,00
16:50:01 all 0,00 0,00 0,01 0,00 0,00 99,99
17:00:01 all 0,00 0,00 0,00 0,00 0,00 99,99
17:10:02 all 0,00 0,00 0,01 0,00 0,00 99,99
17:20:01 all 0,00 0,02 0,02 0,01 0,00 99,95
17:30:01 all 0,00 0,00 0,01 0,00 0,00 99,99
17:40:01 all 0,00 0,00 0,00 0,00 0,00 99,99
17:50:01 all 0,00 0,00 0,00 0,00 0,00 99,99
18:00:01 all 0,00 0,00 0,00 0,00 0,00 99,99
18:10:01 all 0,00 0,00 0,01 0,00 0,00 99,99
18:20:01 all 0,00 0,00 0,00 0,00 0,00 99,99
18:30:01 all 0,00 0,00 0,00 0,00 0,00 99,99
18:40:01 all 0,00 0,00 0,01 0,00 0,00 99,99
18:50:01 all 0,01 0,00 0,05 0,01 0,00 99,93
19:00:01 all 0,01 0,00 0,04 0,01 0,00 99,95
19:10:01 all 0,01 0,00 0,02 0,01 0,00 99,96
19:20:01 all 0,00 0,00 0,01 0,00 0,00 99,99
19:30:01 all 0,00 0,00 0,00 0,00 0,00 100,00
19:40:01 all 0,00 0,00 0,01 0,00 0,00 99,98
19:50:01 all 0,00 0,00 0,02 0,00 0,00 99,98
20:00:01 all 0,01 0,00 0,05 0,01 0,00 99,93
The call to awk will be made from a bash script.
This is easier with
cut
:With this you are telling it to print from the third to the last field.
If the delimiter is a tab, you must indicate it with
-d$'\t'
.Examples: Gets from the 3rd to the last field:
Get only the third field: