Question

I'm using gcov to get the code coverage results from my program, it works great but I want to remove the results from files that have 0% coverage.

It prints off the desired output to stdout, but I get the additional output in the format

File [directory]
Lines executed:0.00% of [lines]
[newline]

And that is the output I want to remove. There are other Files, but their coverage value is greater than 0.00% and therefore I want them to stay. I just want the line before and after 0.00% to be removed.

So I basically want to do grep -v -C 1 :0.00%

Except that isn't working, grep -C 1 :0.00% matches what I want to remove, and grep -v :0.00% removes just the 0% lines, but they don't work together. Is there another grep-like tool that does this or do I just have the format wrong?

Was it helpful?

Solution

I just want the line before and after 0.00% to be removed.

You could use GNU sed:

sed 'N;/\n.*0.00%.*/!{P;D};N;d' inputfile

OTHER TIPS

Using GNU awk for multi-char RS;

$ cat file
foo
File [directory]
Lines executed:0.00% of [lines]
[newline]
bar

$ gawk -v RS='^$' -v ORS= '{sub(/[^\n]+\n[^\n]+:0.00%[^\n]+\n[^\n]+\n/,"")}1' file
foo
bar

The above just looks for the RE that describes a line containing :0.00% (i.e. [^\n]+:0.00%[^\n]+\n) and then removes it along with the line before it (i.e. [^\n]+\n) and the line after it (same RE).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top