gpt4 book ai didi

linux - 如何将输出格式化为列?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:24:33 25 4
gpt4 key购买 nike

我如何修改以下脚本,使其在相应的列中显示每个值:脚本的主体如下所示:

( $vmdisk, $totalio, $readpercentage, $cachehitpercentage, $currentkbpersecond,
$maximumkbpersecond, $currentiopersecond, $maximumiopersecond
) = split (",", $line);
$totalio =~ s/\"//g;
$readpercentage =~ s/\"//g;
$cachehitpercentage =~ s/\"//g;
$currentkbpersecond =~ s/\"//g;
$maximumkbpersecond =~ s/\"//g;
$currentiopersecond =~ s/\"//g;
$maximumiopersecond =~ s/\"//g;

print "totalio:$totalio readpercentage:$readpercentage cachehitpercentage:$cachehitpercentage currentkbpersecond:$currentkbpersecond maximumkbpersecond:$maximumkbpersecond currentiopersecond:$currentiopersecond maximumiopersecond:$maximumiopersecond";

这将显示这种类型的格式化输出:

totalio:75.0 readpercentage:20.0 cachehitpercentage:93.3 currentkbpersecond:33.8 maximumkbpersecond:33.8 currentiopersecond:15.0 maximumiopersecond:15.0

一切都在一行中。我的目标是将输出放入列中并使其更具可读性。例如像这样:

totalio readpercentage cachehitpercentage

75.00 20.0 93.0

我该怎么做?

最佳答案



 printf "%-10s %-10s %-10s\n", $totalio, $readpercentage, $cachehitpercentage;

应该做你正在寻找的。只需根据需要根据模式附加变量即可。引用:printf

关于linux - 如何将输出格式化为列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13323666/

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