Q:

Printing the second frame of top output

When I execute the "top" command without any flags, I get 
with about a dozen processes using at least 0.1% memory and CPU.
When I print this to a file using a cronjob set to run every minute, which executes the command below, however, I only get two or three processes using more than 0.1% memory and CPU. 
The cronjob executes this command:
top -b -n 1 | sed -n '8,17p' | sed 's/^ *//' | tr -s ' ' | sed 's/ /", "/g ; s/^/{"/g ; s/$/"},/g ; 1s/^/[/ ; $ s/.$/]/ ; s/"/"pid": "/1 ; s/"/"user": "/5 ; s/"/"pr": "/9 ; s/"/"ni": "/13 ; s/"/"virt": "/17 ; s/"/"res": "/21 ; s/"/"shr": "/25 ; s/"/"s": "/29 ; s/"/"cpu": "/33 ; s/"/"mem": "/37 ; s/"/"time": "/41 ; s/"/"command": "/45 ; s/"\(-\?[0-9]\+\)"/\1/g'
which takes the first frame of "top" in batch mode and returns it in JSON format, e.g. something like this:
[
    {
        "pid": 7303,
        "user": "fahclie+",
        "pr": 39,
        "ni": 19,
        "virt": 255736,
        "res": 14716,
        "shr": 5556,
        "s": "S",
        "cpu": "400,9",
        "mem": "0,2",
        "time": "210:15.98",
        "command": "FahCore_a4"
    },
    {
        "pid": 1,
        "user": "root",
        "pr": 20,
        "ni": 0,
        "virt": 42040,
        "res": 4664,
        "shr": 2840,
        "s": "S",
        "cpu": "0,0",
        "mem": "0,1",
        "time": "0:01.16",
        "command": "init"
    },
    {
        "pid": 2,
        "user": "root",
        "pr": 20,
        "ni": 0,
        "virt": 0,
        "res": 0,
        "shr": 0,
        "s": "S",
        "cpu": "0,0",
        "mem": "0,0",
        "time": "0:00.00",
        "command": "kthreadd"
    },
    {
        "pid": 3,
        "user": "root",
        "pr": 20,
        "ni": 0,
        "virt": 0,
        "res": 0,
        "shr": 0,
        "s": "S",
        "cpu": "0,0",
        "mem": "0,0",
        "time": "0:00.13",
        "command": "ksoftirqd/0"
    },
    {
        "pid": 5,
        "user": "root",
        "pr": 0,
        "ni": -20,
        "virt": 0,
        "res": 0,
        "shr": 0,
        "s": "S",
        "cpu": "0,0",
        "mem": "0,0",
        "time": "0:00.00",
        "command": "kworker/0:+"
    },
    {
        "pid": 7,
        "user": "root",
        "pr": 20,
        "ni": 0,
        "virt": 0,
        "res": 0,
        "shr": 0,
        "s": "S",
        "cpu": "0,0",
        "mem": "0,0",
        "time": "0:03.58",
        "command": "rcu_sched"
    },
    {
        "pid": 8,
        "user": "root",
        "pr": 20,
        "ni": 0,
        "virt": 0,
        "res": 0,
        "shr": 0,
        "s": "S",
        "cpu": "0,0",
        "mem": "0,0",
        "time": "0:00.00",
        "command": "rcu_bh"
    },
    {
        "pid": 9,
        "user": "root",
        "pr": 20,
        "ni": 0,
        "virt": 0,
        "res": 0,
        "shr": 0,
        "s": "S",
        "cpu": "0,0",
        "mem": "0,0",
        "time": "0:01.26",
        "command": "rcuos/0"
    },
    {
        "pid": 10,
        "user": "root",
        "pr": 20,
        "ni": 0,
        "virt": 0,
        "res": 0,
        "shr": 0,
        "s": "S",
        "cpu": "0,0",
        "mem": "0,0",
        "time": "0:00.00",
        "command": "rcuob/0"
    },
    {
        "pid": 11,
        "user": "root",
        "pr": "rt",
        "ni": 0,
        "virt": 0,
        "res": 0,
        "shr": 0,
        "s": "S",
        "cpu": "0,0",
        "mem": "0,0",
        "time": "0:00.51",
        "command": "migration/0"
    }

]

Note how from the third processes onward, none of these processes use over 0.0% memory or CPU.
I suspect this is because the first frame of top is the one being written, while during the first frame, top is still gathering process information.
Is there a way to print the second frame to a file instead?

A:

I found the answer thanks to jamesd in freenode's #bash IRC channel:
First we use top -b -n 2 to return the first 2 frames.
We then pipe these frames to grep -A10 'PID USER' (10 being the number of trailing context lines after the matching line, and 'PID USER' the beginning of the headings line), and in turn pipe the result of this to tail -n 10 to get rid of the headings line.
This shows only the top 10 processes of the second frame of top.
10 can of course be swapped out for the desired number of processes, and 'PID USER' for whichever fields come first in the headings line of your personal top configuration.

