下面是我为从命令获取数组中的各个列而编写的代码
while read -r var
do
MemModCondHP=`command`
printf '%s\n' "$MemModCondHP" >> ${var}_MemModCondHP.txt
HPSlNoFromMemModCond=`cat ${var}_MemModCondHP.txt | cut -d= -f1`
HPStatus=`cat ${var}_MemModCondHP.txt | cut -d= -f2`
done < HP_S_List.txt
我的服务器名称在$var
中,我正在这样做以获取服务器列表。
现在我需要根据上述数据创建一个如下所示的文本文件
sevrername;HPSlNoFromMemModCond1;HPStatus1
sevrername;HPSlNoFromMemModCond2;HPStatus2
sevrername;HPSlNoFromMemModCond3;HPStatus3
请让我知道该怎么做。
答案 0 :(得分:0)
只需在脚本中添加回显线即可。对于此示例,我将其设置为写output.csv
:
while read -r var
do
MemModCondHP=`command`
printf '%s\n' "$MemModCondHP" >> ${var}_MemModCondHP.txt
HPSlNoFromMemModCond=`cat ${var}_MemModCondHP.txt | cut -d= -f1`
HPStatus=`cat ${var}_MemModCondHP.txt | cut -d= -f2`
echo "${var};${HPSlNoFromMemModCond};${HPStatus}" > output.csv
done < HP_S_List.txt