2

I tried to use tail xxxx.log | nl to get last 10 lines and their line numbers, but nl command only counts the lines of tailed result. Say there're 20 lines in that file, the returned result's actual line number should be from 11 to 20 which is what I want, but 1 to 10 is returned by this command.

  • 1
    tail has no way to know how many lines are in the file without reading it in its entirety. – mosvy Sep 29 '19 at 4:08
1

The issue that you are having is that you first run tail, and then number the resulting lines. This would always number the lines in the output from tail as 1 through to 10.

Swap the order of your commands, i.e. number all lines first with nl, then run tail on that:

nl xxxx.log | tail
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.