Flush 'tail -f' buffer?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












I'm using the following statement (simplified version):



tail -f -c+1 <filename>


in order to pipe a file to a process.



What I've found, though, is that there is a number of lines at the end which are not piped.



A specific example is piping a mysql file, and stopping when the end is reached:



tail -f -c+1 mysqdump.sql | sed '/^-- Dump completed/ q0'


This doesn't work - the last line of the dump -- Dump completed [...] is not piped to sed.



My guess is that the tail -f buffer, in this case, is flushed only when it's full.



Does anybody know how can I workaround this?



=================



I've found the cause - the description is not complete (and the code doesn't exhibit the behavior).



The problem happens when piping from a compressed (lzma) file:



tail -f -c+1 <filename.lzma> | lzma -d | sed '/^-- Dump completed/ q0'


Most likely, tail is not sending the last compressed block, because it doesn't detect any new line, as the input is binary.










share|improve this question



















  • 2




    See e.g. stackoverflow.com/questions/5295430/… for an answer.
    – jofel
    Aug 30 '12 at 13:40










  • I don't understand your means.before tail and after tail what do you do?
    – PersianGulf
    Aug 30 '12 at 18:34










  • and especially read the BashFAQ entry linked to in that stackoverflow question, mywiki.wooledge.org/BashFAQ/009
    – cas
    Aug 30 '12 at 22:59














up vote
5
down vote

favorite
1












I'm using the following statement (simplified version):



tail -f -c+1 <filename>


in order to pipe a file to a process.



What I've found, though, is that there is a number of lines at the end which are not piped.



A specific example is piping a mysql file, and stopping when the end is reached:



tail -f -c+1 mysqdump.sql | sed '/^-- Dump completed/ q0'


This doesn't work - the last line of the dump -- Dump completed [...] is not piped to sed.



My guess is that the tail -f buffer, in this case, is flushed only when it's full.



Does anybody know how can I workaround this?



=================



I've found the cause - the description is not complete (and the code doesn't exhibit the behavior).



The problem happens when piping from a compressed (lzma) file:



tail -f -c+1 <filename.lzma> | lzma -d | sed '/^-- Dump completed/ q0'


Most likely, tail is not sending the last compressed block, because it doesn't detect any new line, as the input is binary.










share|improve this question



















  • 2




    See e.g. stackoverflow.com/questions/5295430/… for an answer.
    – jofel
    Aug 30 '12 at 13:40










  • I don't understand your means.before tail and after tail what do you do?
    – PersianGulf
    Aug 30 '12 at 18:34










  • and especially read the BashFAQ entry linked to in that stackoverflow question, mywiki.wooledge.org/BashFAQ/009
    – cas
    Aug 30 '12 at 22:59












up vote
5
down vote

favorite
1









up vote
5
down vote

favorite
1






1





I'm using the following statement (simplified version):



tail -f -c+1 <filename>


in order to pipe a file to a process.



What I've found, though, is that there is a number of lines at the end which are not piped.



A specific example is piping a mysql file, and stopping when the end is reached:



tail -f -c+1 mysqdump.sql | sed '/^-- Dump completed/ q0'


This doesn't work - the last line of the dump -- Dump completed [...] is not piped to sed.



My guess is that the tail -f buffer, in this case, is flushed only when it's full.



Does anybody know how can I workaround this?



=================



I've found the cause - the description is not complete (and the code doesn't exhibit the behavior).



The problem happens when piping from a compressed (lzma) file:



tail -f -c+1 <filename.lzma> | lzma -d | sed '/^-- Dump completed/ q0'


Most likely, tail is not sending the last compressed block, because it doesn't detect any new line, as the input is binary.










share|improve this question















I'm using the following statement (simplified version):



tail -f -c+1 <filename>


in order to pipe a file to a process.



What I've found, though, is that there is a number of lines at the end which are not piped.



A specific example is piping a mysql file, and stopping when the end is reached:



tail -f -c+1 mysqdump.sql | sed '/^-- Dump completed/ q0'


This doesn't work - the last line of the dump -- Dump completed [...] is not piped to sed.



My guess is that the tail -f buffer, in this case, is flushed only when it's full.



Does anybody know how can I workaround this?



=================



I've found the cause - the description is not complete (and the code doesn't exhibit the behavior).



The problem happens when piping from a compressed (lzma) file:



tail -f -c+1 <filename.lzma> | lzma -d | sed '/^-- Dump completed/ q0'


Most likely, tail is not sending the last compressed block, because it doesn't detect any new line, as the input is binary.







pipe tail






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 31 '12 at 8:40

























asked Aug 30 '12 at 13:02









Marcus

292315




292315







  • 2




    See e.g. stackoverflow.com/questions/5295430/… for an answer.
    – jofel
    Aug 30 '12 at 13:40










  • I don't understand your means.before tail and after tail what do you do?
    – PersianGulf
    Aug 30 '12 at 18:34










  • and especially read the BashFAQ entry linked to in that stackoverflow question, mywiki.wooledge.org/BashFAQ/009
    – cas
    Aug 30 '12 at 22:59












  • 2




    See e.g. stackoverflow.com/questions/5295430/… for an answer.
    – jofel
    Aug 30 '12 at 13:40










  • I don't understand your means.before tail and after tail what do you do?
    – PersianGulf
    Aug 30 '12 at 18:34










  • and especially read the BashFAQ entry linked to in that stackoverflow question, mywiki.wooledge.org/BashFAQ/009
    – cas
    Aug 30 '12 at 22:59







2




2




See e.g. stackoverflow.com/questions/5295430/… for an answer.
– jofel
Aug 30 '12 at 13:40




See e.g. stackoverflow.com/questions/5295430/… for an answer.
– jofel
Aug 30 '12 at 13:40












I don't understand your means.before tail and after tail what do you do?
– PersianGulf
Aug 30 '12 at 18:34




I don't understand your means.before tail and after tail what do you do?
– PersianGulf
Aug 30 '12 at 18:34












and especially read the BashFAQ entry linked to in that stackoverflow question, mywiki.wooledge.org/BashFAQ/009
– cas
Aug 30 '12 at 22:59




and especially read the BashFAQ entry linked to in that stackoverflow question, mywiki.wooledge.org/BashFAQ/009
– cas
Aug 30 '12 at 22:59










2 Answers
2






active

oldest

votes

















up vote
8
down vote



accepted










tail -f flushes after every input line. You can confirm this with strace (or truss or whatever your unix variant provides to trace processes' system calls).



If there is an incomplete line, tail -f keeps waiting for the next newline. It's a tool designed for text files. If you need to tail a binary file (e.g. if -- Dump completed is not followed by a newline), you'll have to use a custom tool.



If you've redirected sed's output away from the terminal, it will be doing its own buffering. Try stdbuf or unbuffer.






share|improve this answer






















  • I was in fact executing on a binary file being remotely copied (I purposely don't want to use "ssh cat"). I worked the problem around using scp on a named pipe.
    – Marcus
    Aug 31 '12 at 8:41











  • For sed you can use -u if you don't want buffer
    – agate
    Jul 10 at 16:59

















up vote
1
down vote













Example using stdbuf -o0. Reference: https://superuser.com/a/1123674/126847



tail -F cpu.log | stdbuf -o0 tr '=' ' ' | stdbuf -o0 awk '$6 > 1'





share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f46723%2fflush-tail-f-buffer%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    8
    down vote



    accepted










    tail -f flushes after every input line. You can confirm this with strace (or truss or whatever your unix variant provides to trace processes' system calls).



    If there is an incomplete line, tail -f keeps waiting for the next newline. It's a tool designed for text files. If you need to tail a binary file (e.g. if -- Dump completed is not followed by a newline), you'll have to use a custom tool.



    If you've redirected sed's output away from the terminal, it will be doing its own buffering. Try stdbuf or unbuffer.






    share|improve this answer






















    • I was in fact executing on a binary file being remotely copied (I purposely don't want to use "ssh cat"). I worked the problem around using scp on a named pipe.
      – Marcus
      Aug 31 '12 at 8:41











    • For sed you can use -u if you don't want buffer
      – agate
      Jul 10 at 16:59














    up vote
    8
    down vote



    accepted










    tail -f flushes after every input line. You can confirm this with strace (or truss or whatever your unix variant provides to trace processes' system calls).



    If there is an incomplete line, tail -f keeps waiting for the next newline. It's a tool designed for text files. If you need to tail a binary file (e.g. if -- Dump completed is not followed by a newline), you'll have to use a custom tool.



    If you've redirected sed's output away from the terminal, it will be doing its own buffering. Try stdbuf or unbuffer.






    share|improve this answer






















    • I was in fact executing on a binary file being remotely copied (I purposely don't want to use "ssh cat"). I worked the problem around using scp on a named pipe.
      – Marcus
      Aug 31 '12 at 8:41











    • For sed you can use -u if you don't want buffer
      – agate
      Jul 10 at 16:59












    up vote
    8
    down vote



    accepted







    up vote
    8
    down vote



    accepted






    tail -f flushes after every input line. You can confirm this with strace (or truss or whatever your unix variant provides to trace processes' system calls).



    If there is an incomplete line, tail -f keeps waiting for the next newline. It's a tool designed for text files. If you need to tail a binary file (e.g. if -- Dump completed is not followed by a newline), you'll have to use a custom tool.



    If you've redirected sed's output away from the terminal, it will be doing its own buffering. Try stdbuf or unbuffer.






    share|improve this answer














    tail -f flushes after every input line. You can confirm this with strace (or truss or whatever your unix variant provides to trace processes' system calls).



    If there is an incomplete line, tail -f keeps waiting for the next newline. It's a tool designed for text files. If you need to tail a binary file (e.g. if -- Dump completed is not followed by a newline), you'll have to use a custom tool.



    If you've redirected sed's output away from the terminal, it will be doing its own buffering. Try stdbuf or unbuffer.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 13 '17 at 12:36









    Community♦

    1




    1










    answered Aug 31 '12 at 1:05









    Gilles

    512k12010151547




    512k12010151547











    • I was in fact executing on a binary file being remotely copied (I purposely don't want to use "ssh cat"). I worked the problem around using scp on a named pipe.
      – Marcus
      Aug 31 '12 at 8:41











    • For sed you can use -u if you don't want buffer
      – agate
      Jul 10 at 16:59
















    • I was in fact executing on a binary file being remotely copied (I purposely don't want to use "ssh cat"). I worked the problem around using scp on a named pipe.
      – Marcus
      Aug 31 '12 at 8:41











    • For sed you can use -u if you don't want buffer
      – agate
      Jul 10 at 16:59















    I was in fact executing on a binary file being remotely copied (I purposely don't want to use "ssh cat"). I worked the problem around using scp on a named pipe.
    – Marcus
    Aug 31 '12 at 8:41





    I was in fact executing on a binary file being remotely copied (I purposely don't want to use "ssh cat"). I worked the problem around using scp on a named pipe.
    – Marcus
    Aug 31 '12 at 8:41













    For sed you can use -u if you don't want buffer
    – agate
    Jul 10 at 16:59




    For sed you can use -u if you don't want buffer
    – agate
    Jul 10 at 16:59












    up vote
    1
    down vote













    Example using stdbuf -o0. Reference: https://superuser.com/a/1123674/126847



    tail -F cpu.log | stdbuf -o0 tr '=' ' ' | stdbuf -o0 awk '$6 > 1'





    share|improve this answer
























      up vote
      1
      down vote













      Example using stdbuf -o0. Reference: https://superuser.com/a/1123674/126847



      tail -F cpu.log | stdbuf -o0 tr '=' ' ' | stdbuf -o0 awk '$6 > 1'





      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        Example using stdbuf -o0. Reference: https://superuser.com/a/1123674/126847



        tail -F cpu.log | stdbuf -o0 tr '=' ' ' | stdbuf -o0 awk '$6 > 1'





        share|improve this answer












        Example using stdbuf -o0. Reference: https://superuser.com/a/1123674/126847



        tail -F cpu.log | stdbuf -o0 tr '=' ' ' | stdbuf -o0 awk '$6 > 1'






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 25 at 13:43









        JohnMudd

        1707




        1707



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f46723%2fflush-tail-f-buffer%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?