Это дает вам доступ ко всем данным во входном файле по имени этого значения:
$ cat tst.awk
BEGIN { FS = "[[:space:]]*[|][[:space:]]*" }
{ gsub(/^[[:space:]]+|[[:space:]]+$/,"") }
prev1 ~ /^[-|]+$/ {
split(prev2,tags)
for (i=1; i<=NF; i++) {
tag = tags[i]
val = $i
tag2val[tag] = val
}
}
{ prev2 = prev1; prev1 = $0 }
END {
for (tag in tag2val) {
val = tag2val[tag]
printf "%s = <%s>\n", tag, val
}
print "---"
print tag2val["unused"]
}
$ awk -f tst.awk file
reserved = <111360 KB>
unallocated space = <11157.80 MB>
database_name = <web>
data = <11560 KB>
database_size = <11120.00 MB>
index_size = <11160 KB>
unused = <111640 KB>
---
111640 KB
Если вы хотите вывод в формате CSV, просто настройте раздел END:
$ cat tst.awk
BEGIN { FS = "[[:space:]]*[|][[:space:]]*" }
{ gsub(/^[[:space:]]+|[[:space:]]+$/,"") }
prev1 ~ /^[-|]+$/ {
split(prev2,tags)
for (i=1; i<=NF; i++) {
tag = tags[i]
val = $i
tag2val[tag] = val
}
}
{ prev2 = prev1; prev1 = $0 }
END {
sep = ""
for (tag in tag2val) {
printf "%s%s", sep, tag
sep = ","
}
print ""
sep = ""
for (tag in tag2val) {
printf "%s%s", sep, tag2val[tag]
sep = ","
}
print ""
}
$ awk -f tst.awk file
reserved,unallocated space,database_name,data,database_size,index_size,unused
111360 KB,11157.80 MB,web,11560 KB,11120.00 MB,11160 KB,111640 KB