I'm running a cron job which should get only the last result of iostat -d 1 2. This requires some parsing: What is the simplest way to get either the last set of non-empty lines from standard input to standard output if the length of each set is unknown?
Bad/non-working solutions:
tailsince I'd still need to count the number of lines in the last set.iostat -d 1 2 | tail -$(echo "$(iostat -d 1 2 | wc -l) / 2" | bc)depends on equal set sizes.split/csplitsince they output to file, and keep the useless part of the data.iostat -d 1 2 | sed '1,/^$/d' | sed '1,/^$/d'works only in this special case, since it gets the third set of non-empty lines, but also includes any trailing newlines.iostat -d 1 2 | tac | sed '1,/^$/d' | sed '/^$/q'is a slightly better hack: Reverse and print the first set. However, sinceiostatoutputs an empty line at the end, we first remove that then print until the next empty line in the reversed output. Other commands might output any number of newlines at the end, so it's not a general solution. Reverse again if you want to keep the original sequence.grep -Pwith\Zseems to only detect EOL, not EOF.
