gpt4 book ai didi

linux - 在 Linux 中的单个列上进行 Grep

转载 作者:IT王子 更新时间:2023-10-29 01:06:29 24 4
gpt4 key购买 nike

我正在尝试解析 df -h 命令的输出。例如:

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VGExaDb-LVDbSys1
30G 17G 12G 58% /
/dev/sda1 496M 38M 433M 8% /boot
/dev/mapper/VGExaDb-LVDbOra1
99G 18G 76G 19% /u01
tmpfs 252G 90M 252G 1% /dev/shm
dbfs-dbfs_user@:/ 4.0T 283G 3.7T 8% /dbfs_direct

我只想要“可用性”列下的值。但是 awk 命令并没有像我想要的那样工作,因为每行中的单词数不一样。当我运行 df -h | awk '{print $4}' 命令,它给出如下输出:

Avail

58%
433M

19%
252G
3.7T

最佳答案

试试这个:

df -Ph | awk '{ print $4 }'

每个 man 页面:

   -P, --portability
use the POSIX output format

这不会导致不必要的换行。 h 将为您提供人类可读的格式。

关于linux - 在 Linux 中的单个列上进行 Grep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22043937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com