正常情况

  1. [root@6A84935A18948CFB block]# cat /sys/block/sda/stat
  2. 3758907 4275 108729115 1307625 3883092 400210 101613393 6526928 0 2844355 5860981 0 0 0 0

使用 awk 去除多余空格

  1. cat /sys/block/sda/stat | awk '{$1=$1;print}'
  2. 3756794 4251 108640459 1306792 3882578 400026 101600391 6526174 0 2843001 5860024 0 0 0 0

解析为 JSON 数组

  1. cat /sys/block/sda/stat | awk '{$1=$1;print}' | xargs -I{} echo '"{}"' | jq 'split(" ")'
  2. [
  3. "3759352",
  4. "4275",
  5. "108744563",
  6. "1307823",
  7. "3884720",
  8. "400364",
  9. "101641859",
  10. "6528584",
  11. "0",
  12. "2845230",
  13. "5862519",
  14. "0",
  15. "0",
  16. "0",
  17. "0"
  18. ]