从" sysstat"的输出中获取特定字段

时间:2015-09-07 19:32:42

标签: linux unix awk grep

我如何只从时间和%空闲列中获取数字?

http://imgur.com/vsclJQO

这些结果来自 sysstat

我希望它看起来像

Time        $idle
4:02:58 AM   100.00
4:02:59 AM   100.00
   .           .
   .           .
   .           .

到目前为止,我尝试使用awk是:

#!/bin/sh
while true
do
cpu0=$(sar 1 1 | awk '{print $1, $9}')
echo $cpu0 >> test.file
        sleep 4
done

然而,它给了我

Linux 04:02:58 %idle 04:02:59 100.00 Average:

如果我在$ 9之后添加\ n,它会给我语法错误...

还是有其他办法吗?不使用grep或awk? 谢谢

2 个答案:

答案 0 :(得分:0)

拯救......

// changed to -8
let constraintUsernameLabelHTrailing = NSLayoutConstraint(item: usernameLabel,
    attribute: .Trailing, relatedBy: .Equal, toItem: usernameField,
    attribute: .Leading, multiplier: 1.0, constant: -8)

// changed to -8
let constraintUsernameFieldVBottom = NSLayoutConstraint(item: usernameField,
    attribute: .Bottom, relatedBy: .Equal, toItem: passwordField,
    attribute: .Top, multiplier: 1.0, constant: -8)

// changed to -8
let constraintPasswordLabelHTrailing = NSLayoutConstraint(item: passwordLabel,
    attribute: .Trailing, relatedBy: .Equal, toItem: passwordField,
    attribute: .Leading, multiplier: 1.0, constant: -8)

答案 1 :(得分:0)

只是awk:

awk 'NR==1{ print "Time\t\t"$9 } NR>1{ print $1,$2"\t"$9 }' input.txt