作者hungwei0331 (Game)
看板LinuxDev
標題[問題] shell script擷取文字問題
時間Wed Sep 10 16:57:18 2014
小弟想擷取shell script系統時間至PHP前端顯示, 輸入指令是 --> uptime
得到結果 16:51:49 up 1 day, 13:10, 1 user, load average: 0.23, 0.48, 0.48
但如果只想擷取 up 1 day, 13:10 這個字串要如何處裡呢?
已經試過用 uptime | cut -c 10-25 ,但考慮到天數破100時抓取會錯誤
變成100 day, 13:10 而導致up消失
還請版上前輩多多指教 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.248.56.181
※ 文章網址: http://webptt.com/m.aspx?n=bbs/LinuxDev/M.1410339440.A.24A.html
1F:推 filiaslayers: 用awk 09/10 16:59
2F:→ hungwei0331: 已經順利解決, 謝謝前輩 09/10 17:26
3F:→ jserv: 可以分享解法嗎?感謝 09/10 21:14
4F:→ kerwinhui: 為什麼不用 uptime -p ? 09/10 21:29
5F:→ mshockwave: regular expression 09/11 00:03
6F:→ hungwei0331: 好像沒有uptime -p 只有- v而已 ? 09/11 13:43
7F:→ kerwinhui: 有 -p, --pretty (show uptime in pretty format) 09/11 15:43
8F:→ kerwinhui: procps-ng 會有 (這邊測試 arch linux…) 09/11 15:47
9F:→ filiaslayers: 我試了一下,arch有-p參數,但ubuntu沒有 09/11 16:40
10F:→ kerwinhui: procps-ng 3.3.9 新加的 (redhat bug#789091) 09/11 21:55