1752577 Members
5526 Online
108788 Solutions
New Discussion юеВ

Re: tail command foo

 
SOLVED
Go to solution
jerry1
Super Advisor

tail command foo

Why does tail only tail 703 lines to a file.

If I tail -5000 a file that has 50000 lines
I get 5000 lines.

If I tail -5000 and redirect > to another
file name I only get 703 lines.

Does anyone know why?

11 REPLIES 11
John Poff
Honored Contributor
Solution

Re: tail command foo

Hi,

The 'tail' command actually has a 20K byte buffer, which will limit the actual number of lines you can get from it, depending on the size of your lines.

You might want to use Perl or awk to see if you can get what you need.

JP
John Poff
Honored Contributor

Re: tail command foo

From the 'tail' man page:

" Tails relative to end-of-file are stored in a 20-Kbyte buffer, and
thus are limited in length. Therefore, be wary of the results when
piping output from other commands into tail."


JP

Re: tail command foo

yes it is a problem of tail buffer size limitation
regards
SK
Your imagination is the preview of your life's coming attractions
jerry1
Super Advisor

Re: tail command foo

Can tail be modified to output more lines?

Pete Randall
Outstanding Contributor

Re: tail command foo

Sorry, no. However you could try something with sed like this:

# print last 10 lines of file (emulates "tail")
sed -e :a -e '$q;N;11,$D;ba'

Change the "11" to whatever number you're trying to retrieve.


Pete

Pete
Henry Chua
Super Advisor

Re: tail command foo

As said, tail has a limited buffer..
awk will be the answer.. its really powerful
Muthukumar_5
Honored Contributor

Re: tail command foo

You can use awk as,

awk '{ if ( NR >= 10 ) print $0 }' file

So that it will print the liens after line number 10 there


Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: tail command foo

Attachment a shell script, it will be helpful to get less lines on standard ouput and to get files.

Try to create a file as,

vi /usr/bin/less


chmod 755 /usr/bin/less

You can test as,

echo "bye\nfor\nnow" | less 2

It will give
for
now there.

You can test the files too as,

less 2 /usr/bin/less
# Normal end
exit 0

It will be used there. You can edit to make it efficient more.

HTH.
-Muthu
Easy to suggest when don't know about the problem!
subbukns
New Member

Re: tail command foo

Hi Pete

sed -e :a -e '$q;N;'$cnt',$D;ba' abc.txt > xyz.txt

Could you please explain me the above statement -- phrase wise.

as early as possible.

Thanks,
Subbu