5

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

2 Answers 2

5

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.

0
0

your command | tail -n

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

so for your need,

your command | tail -1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .