[英]Please help modifying the shell script in linux
I have a shell script that do the following task: 我有一个执行以下任务的shell脚本:
ec2-describe-instances
commands and write this detail to a file. ec2-describe-instances
命令中提取标签(名称,所有者,cost.centre),并将此详细信息写入文件。 Any lead is appreciated 任何线索表示赞赏
Forget yours, I have recommended to use 2-d array in awk to simplify the code. 忘记了,我建议在awk中使用二维数组以简化代码。
Here is the updates from your previous question ( Error in shell script and how to write to a file ) 这是上一个问题的更新( shell脚本中的错误以及如何写入文件 )
awk 'BEGIN{print "Instance id Name Owner Cost.centre"}
/TAG/{split($0,a,FS);a[4]=tolower(a[4]);$1=$2=$3=$4="";b[a[3],a[4]]=$0;c[a[3]]}
END{for (i in c) printf "%-18s%-26s%-14s%-20s\n",i,b[i,"name"]==""?"Unknown":b[i,"name"],b[i,"owner"]==""?"Unknown":b[i,"owner"],b[i,"cost.center"]==""?"Unknown":b[i,"cost.center"]}' file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.