Using AWK
hpasmcli -s "show dimm" | awk '
/^Module/ { m = m sprintf("%4s", $3) }
/^Status/ { s = s sprintf("%4s", $2) }
END { print "Module:" m "\n" "Status:" s }'
Sample output:
Module: 1 3 6 8 1 3 6 8
Status: Ok Ok Ok Ok Ok Ok Ok Ok
The blocks in curly braces after regular expressions /^Module/ and /^Status/ are executed when the current record (line) matches the corresponding regular expression. The values are collected into m and s variables. At the END, both variables are printed to the standard output.
sprintf functions return the strings padded to the specified width (4).
Alternatively, split the records with a colon using -F: option. But then you will need to trim the values using gsub function, for instance:
hpasmcli -s "show dimm" | awk -F: '
/^Module/ { gsub(/ +/, "", $2); m = m sprintf("%4s", $2) }
/^Status/ { gsub(/ +/, "", $2); s = s sprintf("%4s", $2) }
END { print "Module:" m "\n" "Status:" s }'
Using Perl
hpasmcli -s "show dimm" | perl -e '
while (<>) {
push @m, m/:\s*(\S+)$/ if /^Module/;
push @s, m/:\s*(\S+)$/ if /^Status/;
}
print "Module: ", join("", map { sprintf "%4s", $_ } @m), "\n";
print "Status: ", join("", map { sprintf "%4s", $_ } @s), "\n";'
The while loop reads the input line by line. If a line starts with "Module", then the value is extracted from the line using m/:\s*(\S+)$/ expression. The matching group of non-space characters (\S+) is added to @m, or @s arrays. Finally, the array items are joined and printed to the standard output.