Search code examples
linuxbashtail

tail -f, but only every 1000th row


tail -f myfile.log

is very nice, but if you have a big file you may only want to display every nth row.

So the output will show row 1, row 1001, row 2001 and so on.

Is this possible or do the output needs to be chained into sed, awk or something else?


Solution

  • Using awk:

    $ awk 'NR%1000==1'
    

    Sample every 3rd:

    $ seq 1 10 | awk 'NR%3==1'
    1
    4
    7
    10