通过Shell脚本在命令输出中添加一列

时间:2017-03-07 11:16:59

标签: shell

[root@vms01 ~]# xm list

Name                                        ID   Mem VCPUs      State   Time(s)

0004fb00000600000484f2c141c45ebd             2 32768     8     r----- 17545619.9
0004fb000006000010777a59f9d0789a           568 33083     4     -b----  92648.9
0004fb00000600001ebd7c8a657da3a7           504  4096     2     r----- 164842.4

现在我需要添加一个列"简单名称"在最后。我如何通过shell脚本实现它?

1 个答案:

答案 0 :(得分:0)

这个怎么样:

xm list | while IFS='' read x; do printf "%-83s %s\n" "$x" "Simple Name"; done
Name                                        ID   Mem VCPUs      State   Time(s)     Simple Name
Domain-0                                     0  1793     2     r----- 1815788.7     Simple Name
18732649712347                            4563 16384     1     r-----   3553.7      Simple Name
86734762346293                            4567 16384     1     r-----   2967.5      Simple Name
98634963425246                            4569  8192     8     r-----  11244.8      Simple Name
32472034857723045974                      2348  4000     8     r----- 11252960.7    Simple Name
2234827345084                              535 128000    32     r----- 55286918.7   Simple Name
947305273405782034523457                       16000     1                30.6      Simple Name