歡迎您光臨本站 註冊首頁

liunx命令行解析csv格式內容

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

如題,現在想使用命令行方式解析top命令的返回:

top - 13:13:02 up  4:17,  1 user,  load average: 0.15, 0.05, 0.01
Tasks: 120 total,   1 running, 119 sleeping,   0 stopped,   0 zombie
Cpu(s):  1.1%us,  0.2%sy,  0.0%ni, 97.6%id,  0.9%wa,  0.0%hi,  0.2%si,  0.0%st
Mem:   3925152k total,  3587764k used,   337388k free,   160976k buffers
Swap: 10207224k total,        0k used, 10207224k free,   478228k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                   
11870 root      20   0 15084 1100  832 R  1.8  0.0   0:00.07 top                                                                                                      
    1 root      20   0 19396 1564 1256 S  0.0  0.0   0:01.07 init                                                                                                      
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                                                                  
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                                                               
    4 root      20   0     0    0    0 S  0.0  0.0   0:00.45 ksoftirqd/0                                                                                               
    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                                                               
    6 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0                                                                                                
    7 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/1                                                                                               
    8 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/1                                                                                               
    9 root      20   0     0    0    0 S  0.0  0.0   0:00.16 ksoftirqd/1                                                                                               
   10 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/1                                                                                                
   11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events/0                                                                                                  
   12 root      20   0     0    0    0 S  0.0  0.0   0:00.03 events/1                                                                                                  
   13 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cpuset                                                                                                   
   14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper                                                                                                   
   15 root      20   0     0    0    0 S  0.0  0.0   0:00.01 netns                                                                                                     
   16 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr                                                                                                
   17 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm               
現在想得到的結果如下:
%CPU %MEM
1.8  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0
0.0  0.0

ps aux | awk '{print $3,$4}'
top -b -n 1 | awk 'NR>6{print $9,$10}'
ps -eo pcpu,rss,comm

[火星人 ] liunx命令行解析csv格式內容已經有508次圍觀

http://coctec.com/docs/service/show-post-189.html