read the i/p file
count the no. of '\n' characters
if count k (argument of tail) then print all chars till EOF
correct me if m wrong !!!
On Aug 16, 9:16 am, vikas kumar vikas.kumar...@gmail.com wrote:
the method of farword seek is inefficient. consider case of 10
lines and you want to
the method of farword seek is inefficient. consider case of 10
lines and you want to display only 3-4 lines. better seek from end.
use a buffer[buf_size].
let size =filesize.
lc = 0;
while(lc = given line input)
{
fseek(fp, size);
if(size buf_size)
fread(fp, size, buffer);
else
Tail by default displays last 10 lines of file.
1. mmap the file
2. keep two pointers(A, B) pointing to beginning of the file
2. search for 10th \n using B, if not found i.e file has less than
10 lines, print from beginning to end
3. if found, start incrementing both A and B to the next \n.
Tail works on stdin, too. Can't mmap that. The usual way is to
buffer the last N lines read in a ring buffe.r
On Aug 14, 4:22 pm, Prem Mallappa prem.malla...@gmail.com wrote:
Tail by default displays last 10 lines of file.
1. mmap the file
2. keep two pointers(A, B) pointing to beginning of
Enter the lines into a FIFO queue as you read them. After you have
enqueued n lines, dequeue a line every time you enqueue one, so that
the queue will contain the last n (or fewer) lines of the file.
Dave
On Aug 13, 1:13 pm, amit amitjaspal...@gmail.com wrote:
I am trying using fseek but