grep the output between specific lines

Symmetrix ID : 00000001234

Host Name : myown

Identifiers Found : 5000000000000000
5000000000000001

Device Cap(MB) Attr Dir:P
------ ------- ---- ----
1234 25886 (M) 8D:1, 9D:1
0123 25886 (M) 8D:1, 9D:1
1345 25886 (M) 8D:1, 9D:1
1576 17261 (M) 8D:1, 9D:1
1456 17261 (M) 4B:0,13B:0

-----------------------------

MB Total: 363879
GB Total: 355.4
[/CODE]My output should be

myown : 355.4 GB
 
1234    25886
0123    25886
1345    25886
1567    17261
1456    17261

below is awk to get this output myown 355.4

myown : 355.4 GB : 1234,0123,1345,1567,1456

egrep "Host Name|GB Total"|awk '{print $NF}'|sed 'N;s/\n/ /;s/$/ GB/'

please help modifying to get dev and cap as well for each server

You may want to write an awk script...

put the following into a file "filter.awk"

{
    if ($0 ~ /^-/) { dash++ } else { if (dash==1) {out[++outcnt] = sprintf("%s %s",$1, $2) } }
    if (match($0, "Host Name : |GB Total: ")) { hdr[++hdrcnt] = substr($0, RLENGTH + 1)}
}
END { printf("%s : %s GB\n\n", hdr[1], hdr[2]);  for (i=1; i<=outcnt; i++) { print out } }

awk then do

awk -f filter.awk YOURFILE
1 Like

Another awk:

awk '/^[0-9]/{sub(/ *\(.*/,x); v=v RS $0} /Host Name/{n=$4} /GB Total/{print n " : " $3,$1 RS v}' infile

Thanks it worked! can you please explain how the above awk works

Please help me in formatting output as below :

myown : 355.4 GB : 1234,0123,1345,1567,1456

awk '/^Host Name/{sub(/.*: /,"");m=$0;next}
/^[0-9]/ && NF>2{line=(length(line))?line","$1:$1;next}
/^GB Total/{print m " : " $3,$1 " : " line }' file
1 Like