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 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:tail since 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/csplit since 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, since iostat outputs 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 -P with \Z seems to only detect EOL, not EOF.
Get last set of non-empty lines
text processing;sed;awk;perl
You can use awk's paragraph mode (when RS is the empty string). That way each set is one record and you can easily print out the last one.iostat -d 1 2 | awk -vRS= 'END{print}'