parsing output

Can somebody provide a solution to parse the following;

cat /tmp/xxx
 
Name:  QUE_REQU (o.mtaseast-o.dmart) (MTPost queue)
    Number of messages:      66446 (Age       686 min; Size        214 mb)
    Backlog (messages):          0 (Age         0 min)
 
Name:  QUE_REQU (o.mtasnord-o.dmart) (MTPost queue)
    Number of messages:      66750 (Age       343 min; Size        153 mb)
    Backlog (messages):         57 (Age         0 min)
 
Name:  QUE_REQU (o.mtaswest-o.dmart) (MTPost queue)
    Number of messages:      48172 (Age       664 min; Size        123 mb)
    Backlog (messages):          0 (Age         0 min)

What I need is to get everything to the rigth of Name:, Number of messages, number of Backlog.

My output should look like this:

QUE_REQU (o.mtaseast-o.dmart) (MTPost queue) 66446 0
QUE_REQU (o.mtasnord-o.dmart) (MTPost queue) 66750 57
QUE_REQU (o.mtaswest-o.dmart) (MTPost queue) 48172 0

Thanks in advance to all who answer

sed 's/^ *//' INPUTFILE |
perl -00 -ne '/:\s*(.*)\n.*:\s*(\d+).*:\s*(\d+)/s && print "$1 $2 $3\n"'
1 Like

Perfect solution!! Can you just break down the perl part for me as to what its doing

The main part is to say - print one two three :slight_smile:

Ok. The regex reflects the structure of you paragraphs - lines separated by empty lines (sed does some cleaning for it). -00 switch says to perl to read a file by paragraphs. The structure is:

some starting chars (not in the regex)
colon :
spaces \s*
shars (.) - remember them in $1
before newline \n
chars .

before colon :
spaces \s*
remember digits in $2 (\d+)
chars, including newline (for that is /s in the end of the regex) .*
before colon :
spaces \s*
digits to $3 (\d+)
some ending shars (not in the regex)

Though the perl solution works perfect for me I just found out that I don't
have perl installed on all my machines. Therefore, can somebody please
supply me with an AWK or sed to solution.

Thanks in advance to all who answer

Try...

awk '$1=="Name:"{print $2,$3,$4,$5; getline; print $4; getline; print $3}' /tmp/xxx | paste - - - 
1 Like

Through Sed..

sed -n 'H;/^  *$/{x;s/[^:]*: *\(.*\)\n[^:]*: *\([^ ]*\) [^:]*: *\([^ ]*\).*/\1 \2 \3/p}' inputfile