Skip to content


printing stanzas

If you worked with AIX you might have quickly get used to the grep -p stanza: /some/pathto/file to display paragraphs of a file. Unfortunately, other UNIX flavors do not share the same idea of what is “stanza” and their awk does not have the -p option.
Recently, I was tasked with extracting from information from about the not patched packages of a LINUX host.

To generate the report (in text format) I used the following command:

# oscap xccdf eval \
            --results results-cve-`hostname`.xml 
            --report report-cve-`hostname -s`.html \
               com.redhat.rhsa-all.xccdf.xml \
               >>  report-cve-rhnprod.txt 

The resulting text file has the paragraph format.

Title   RHSA-2015:1137: kernel security and bug fix update (Important)
Rule    oval-com.redhat.rhsa-def-20151137
Ident   RHSA-2015-1137
Ident   CVE-2014-9420
Result  pass

Title   RHSA-2015:1139: kernel-rt security, bug fix, and enhancement update (Important)
Rule    oval-com.redhat.rhsa-def-20151139
Ident   RHSA-2015-1139
Ident   CVE-2014-9420
Result  fail

So, how to extract from this file only the “stanzas” which result is fail? Like this:

# awk -vRS= -vORS='\n\n' '/fail/' report-cve-rhnprod.txt

Title   RHSA-2015:1081: kernel security, bug fix, and enhancement update (Important)
Rule    oval-com.redhat.rhsa-def-20151081
Ident   RHSA-2015-1081
Ident   CVE-2014-9419
Ident   CVE-2014-9420
Ident   CVE-2014-9585
Ident   CVE-2015-1805
Ident   CVE-2015-3331
Result  fail

Title   RHSA-2015:1221: kernel security, bug fix, and enhancement update (Moderate)
Rule    oval-com.redhat.rhsa-def-20151221
Ident   RHSA-2015-1221
Ident   CVE-2011-5321
Ident   CVE-2015-1593
Ident   CVE-2015-2830
Ident   CVE-2015-2922
Ident   CVE-2015-3636
Result  fail

Posted in Linux.

Tagged with .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.

WordPress Anti Spam by WP-SpamShield



Copyright © 2016 - 2017 Waldemar Mark Duszyk. All Rights Reserved. Created by Blog Copyright.