[Solved] Error in shell script and how to write to a file [closed]


I think this question is fine now, the input file is good enough after edit, I can fully understand what you ask for now.

With awk, you need learn to use 2-d array, it will simplify the code.

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"],b[i,"owner"],b[i,"cost.center"]}' file

Instance id           Name                      Owner         Cost.centre
i-e1cfc499            Memcached                                               
i-7f4b9300            Test_LB01_Sachin                                        
i-c4260db8            Rishi_Win_SAML            Rishi Pandey                    
i-fb5ca283            CLIQR-DO NOT TOUCH        mataa         1234    

1

solved Error in shell script and how to write to a file [closed]