无法添加空格

无法添加空格

如何使用 sed/echo 或 Linux 中的任何其他命令在输出之间添加空格?

首选输出:

Virtual Machine  Test01 status  Running.
Virtual Disk  Test01 size  61GB
Physical Disk  HITACHI (170)
Physical Disk  HITACHI (171)
Physical Disk  HITACHI (172)   

Virtual Machine  Test02 status  Running.
Virtual Disk  Test02 size  61GB
Physical Disk  HITACHI (163)
Physical Disk  HITACHI (164)
Physical Disk  HITACHI (165)
Physical Disk  HITACHI (173)

Virtual Machine  Test03 status  Running.
Virtual Disk Test03_DISK1 (33) size  61GB
Physical Disk  HITACHI (137)
Physical Disk  HITACHI (138)

我的脚本 o/p:

cat /tmp/test.txt | while read in; do echo -en '\n';  ./ovm_vmdisks -u admin -p xxxxxx -h localhost -v "$in"; done |  sed "s/'//g" | egrep -i "Virtual Machine|Virtual Disk|Physical Disk" |sed "s/://g" > /tmp/Automated/Virtualmachines_DETAILS.txt; cat /tmp/Automated/Virtualmachines_DETAILS.txt

Virtual Machine  Test01 status  Running.
Virtual Disk  Test01 size  61GB
Physical Disk  HITACHI (170)
Physical Disk  HITACHI (171)
Physical Disk  HITACHI (172)    <<<< My First output ends here and right after this i would need spaces
Virtual Machine  Test02 status  Running.
Virtual Disk  Test02 size  61GB
Physical Disk  HITACHI (163)
Physical Disk  HITACHI (164)
Physical Disk  HITACHI (165)
Physical Disk  HITACHI (173)  <<<< Second one and so on
Virtual Machine  Test03 status  Running.
Virtual Disk Test03_DISK1 (33) size  61GB
Physical Disk  HITACHI (137)
Physical Disk  HITACHI (138)

答案1

尝试这个:

sed '2,$s/^Virtual Machine/\n&/' file

答案2

在需要换行的地方写入并清空 echo

例如

echo Foo
echo
echo Bar

结果是...

Foo

Bar

相关内容