Operating System - Linux
1752782 Members
6217 Online
108789 Solutions
New Discussion юеВ

Re: print fields using awk

 
SOLVED
Go to solution
Sandman!
Honored Contributor

Re: print fields suing awk

Try the awk script below. It basically extends JRF's script if there is more than one VG present:

# awk '/VOLUME GROUP/{if(a) printf("%s ",a);a=$3}
/PP SIZE/{if(b) printf("%s ",b);b=$6}
/TOTAL PPs/{if(c) printf("%s ",c);c=$6}
/FREE PPs/{if(d) printf("%s\n",d);d=$6}
END{print a,b,c,d}' inp
lawrenzo
Trusted Contributor

Re: print fields suing awk

Thanks guys,

both examples are good however sandman I will toruble shoot your example and get back to you as no output is displayed.

hello
Dennis Handly
Acclaimed Contributor

Re: print fields using awk

>I will trouble shoot your example and get back to you as no output is displayed.

Hmm, I get output if you assume that you made two copies of your initial lsvg output. Sandman does have the free after the total.

Here my suggested changes that prints complete lines:
awk '
BEGIN { VG=""; SZ=""; FREE=""; TOT="" }
/VOLUME GROUP/ {
   if (VG) print VG "," SZ "," FREE "," TOT
   VG=$3
}
/PP SIZE/ {SZ=$6}
/TOTAL PPs/ {TOT=$6}
/FREE PPs/ {FREE=$6}
END { print VG "," SZ "," FREE "," TOT }'

The BEGIN isn't strictly needed.
You could use OFS like JRF did in his print.