Append new lines to stream, until certain number is reached

I’m using this command, which searches pacman.log for packages updated today and converts them into a conky string:

tail -500 /var/log/pacman.log | grep -e "[$(date +"%Y-%m-%d") [0-5][0-9]:[0-9][0-9]] [ALPM] upgraded" | sed 's/^.*([0-2][0-9]:[0-5][0-9]).*upgraded ([^ ]*).*/${color2}2${goto 250}${color1}1/' | tail -18

With tail -18 the maximum number of lines is 18.

What is the best way to append new lines so that the stream always has 18 lines?


You can do (with a shell with support for zsh’s {x..y} form of brace expansion like zsh, bash, ksh93 or yash -o braceexpand):

  printf '%.0sn' {1..18}
} | tail -n 18

Note that it prepends newline as opposed to appending them. To append, you could do:

your-command | tail -n 18 | awk '{print};END{while (NR++ < 18) print ""}'

Leave a Reply

Your email address will not be published. Required fields are marked *