Sample Header Ad - 728x90

Only pipe output if at least n lines

2 votes
6 answers
233 views
I often want to grep output from processes that include a few header lines. But if grep would remove all actual content lines, I don't want to display the header lines. For this to work I would need a command similar to tail but instead of only returning n lines, it would return *all* lines but only if there are at least n lines (the header). A colleague wrote a small Python tool to do this but it needs installation on all machines where I need to do this. Is there a short command line that can achieve this effect using a standard tool (maybe awk?) ?
Asked by Colin 't Hart (255 rep)
Feb 1, 2023, 08:50 AM
Last activity: Feb 4, 2023, 02:39 PM