Append new lines to stream, until certain number is reached Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Append new lines to stream, until certain number is reached without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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?

Answer

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}
  your-command
} | 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 ""}'
We are here to answer your question about Append new lines to stream, until certain number is reached - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji