我想加入并处理来自 top 命令的两行:
shell> top -p 1 -b -d 1 | egrep '^top|^Cpu'
top - 15:17:45 up 736 days, 4:32, 3 users, load average: 0.06, 0.03, 0.00
Cpu(s): 0.7% us, 0.8% sy, 0.0% ni, 97.1% id, 1.3% wa, 0.0% hi, 0.0% si
当尝试使用 awk 和 sed 命令时,我遇到了麻烦 - 没有产生输出。我将使用哪些命令使输出看起来像这样:
Time: 15:17:45 Cpu(s): 0.7% us, 0.8% sy, 0.0% ni, 97.1% id, 1.3% wa, 0.0% hi, 0.0% si
这是一段可能有用的代码:
shell> echo 'top - 15:17:45 up 736 days, 4:32, 3 users, load average: 0.06, 0.03, 0.00' | awk -F' up' '/^top/ {print "Time: " $1}' | sed 's/top - //'
Time: 15:17:45