Reputation: 127
I have a function in my script and i need it to display the output on a table with a header and hide the ligne that contain RELEASE on the output.
for file in ${list[@]}; do
echo -ne ${file} ${ins} " "; env | grep -i ${file} | cut -f2 -d"="
done
here's the outpuit i get right now :
comp1 installed ! v0.6.2
comptest1 installed ! v2.1.1
comp2 installed ! v2.1.5
comp3 installed ! v0.12.0
1.1.18-RELEASE
comp4 installed ! v0.7.0
expected outpout :
Component status version
comp1 installed ! v0.6.2
comptest1 installed ! v2.1.1
comp2 installed ! v2.1.5
comp3 installed ! v0.12.0
comp4 installed ! v0.7.0
what i've tried :
i tried something like redirecting the output of the echo commant to a temp file and then using
column -t -s "," -o "||" temp.txt
But i didn't work i keep getting errors like No such file or directory.
I tried using printf and awk too
awk '{printf "%-30s|%-18s|%-20s\n",${file},${ins} " "; env | grep -i ${file} | cut -f2 -d"="}'
It didn't work too i keep getting syntax errors.
Upvotes: 0
Views: 2062
Reputation: 4865
awk
script using standard Linux gawk.BEGIN { # run once before processing each line
outputFormat = "%-12s|%-10s|%-8s\n"; # configure line output format
printf (outputFormat, "Component", "Status", "Version"); # output headers
print "---------------------------------"; # set header line
}
/-RELEASE/{next;} # ignore each line containing string "-RELEASE"
{ # each line
printf(outputFormat, $1, $2, $4); # print formated fields
}
$ awk -f script.awk input.txt
Component |Status |Version
---------------------------------
comp1 |installed |v0.6.2
comptest1 |installed |v2.1.1
comp2 |installed |v2.1.5
comp3 |installed |v0.12.0
comp4 |installed |v0.7.0
Upvotes: 3