How do you use tail to get the last line outputted by a program. I've tried the following so far:

echo `cmd` >> stdin && tail -1 stdin

For instance:

henry@henry-pc:~$ echo "abc\n123" >> stdin && tail -1 stdin

You do not have to specify stdout as the output as it is natural. You would want to use a pipe char to pipe the output (stdout) to the tail utility.

You would want do to something like:

printf 'abc\n123\n' | tail -1

This will print 123.


your command | tail -n

here n implies number of lines the user needs to be tailed.

so for your need,

your command | tail -1

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.