back

by stevekemp·9mo ago·view on hn ↗
I think you could replace tail with awk, if you absolute needed to. This is a naive attempt:

   cat /etc/passwd | \
   awk -v n=10 '{ lines[NR] = $0 }
            END{
                for (i = NR - n + 1; i <= NR; i++)
                    if (i > 0) print lines[i]
            }'
1 comments
You can, sure, but, tail seeks to EOF and then goes back until it finds "\n", awk cannot seek, so you must do what you did there, that means the bigger the file the longer the time.

And there's also tail -f, how would you go about doing that? a while loop that sleeps and reopens the file? yuck