Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
abc\n123
share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
+1 excellent! thank you. –  HennyH Oct 30 '13 at 4:52

your command | tail -n

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

so for your need,

your command | tail -1

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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