satch_boogie satch_boogie - 6 months ago 8
Python Question

extract the lines from file with bash or python

Here is my file content which is output of pflogsumm

Host/Domain Summary: Messages Received
---------------------------------------
msg cnt bytes host/domain
-------- ------- -----------
415 5416k abc.com
13 19072 xyz.localdomain

Senders by message count
------------------------
415 alert@example.com
13 root@jelly.localdomain

Recipients by message count
---------------------------
506 alert@apple.com <= Extracter from here to ...
70 info@pafpro.org.us
..
...
19 gems@gmail.com
17 info@aol.com
13 hemdem@gmail.com <= Extract ends here

Senders by message size
-----------------------
5416k alert@google.com
...
...


The output seems to have the information feilds separated by "title" and a "new line". For example
Recipients by message count ...<contents of interest> ... NewLine

I tried with below sed expression but it returns all lines after matching the string
"Recipients by message count"


sed -nr '/.*Recipients by message count/,/\n/ p'


Desired output: All emails under
"Recipients by message count"

Answer

Using awk:

awk '/Recipients by message count/{p=1}!$0{p=0}p' input_file

Will print the Recipients by message count block

Comments