How to pipe to grep play (sox) output?How to avoid delay in output stream pipeHow to output avconv with pipeHow to avoid delay in output stream pipeoutput SoX synthesized sound to fileConvert stream video/x-ms-asf to audio and pipe it to stdin of soxSoX suggestions - Binaural Beats?Troubles with chaining commandsRunning a program output to file, but program asks user for inputError Loading SoXHow to pipe all bash terminal output through commandgetting the uniqueness from extracted grep results BUT with stream as an input

How strictly should I take "Candidates must be local"?

Examples of a statistic that is not independent of sample's distribution?

Virginia employer terminated employee and wants signing bonus returned

When a wind turbine does not produce enough electricity how does the power company compensate for the loss?

Is "history" a male-biased word ("his+story")?

Counting all the hearts

Contract Factories

How to detect if C code (which needs 'extern C') is compiled in C++

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?

Bash script should only kill those instances of another script's that it has launched

Why does the negative sign arise in this thermodynamic relation?

Are all players supposed to be able to see each others' character sheets?

Conservation of Mass and Energy

meaning and function of 幸 in "则幸分我一杯羹"

Plausibility of Mushroom Buildings

Do I really need to have a scientific explanation for my premise?

If I receive an SOS signal, what is the proper response?

Why was Goose renamed from Chewie for the Captain Marvel film?

Distinction between apt-cache and dpkg -l

Is "conspicuously missing" or "conspicuously" the subject of this sentence?

Definition of Statistic

Can I pump my MTB tire to max (55 psi / 380 kPa) without the tube inside bursting?

Find longest word in a string: are any of these algorithms good?



How to pipe to grep play (sox) output?


How to avoid delay in output stream pipeHow to output avconv with pipeHow to avoid delay in output stream pipeoutput SoX synthesized sound to fileConvert stream video/x-ms-asf to audio and pipe it to stdin of soxSoX suggestions - Binaural Beats?Troubles with chaining commandsRunning a program output to file, but program asks user for inputError Loading SoXHow to pipe all bash terminal output through commandgetting the uniqueness from extracted grep results BUT with stream as an input













2















It seems a silly situation: I have this command (for pomodoros):



play -n synth 25:00 pinknoise


I don't want to silent completely the output (-q option), just one part (the header). grep won't work. I'm not sure how that kind of updated output (like in npm install ... works).



Normal output:



File Size: 94.3T 
Encoding: n/a
Channels: 1 @ 32-bit
Samplerate: 48000Hz
Replaygain: off
Duration: unknown

In:0.00% 00:00:01.02 [00:00:00.00] Out:49.2k [======|======] Hd:1.3 Clip:0


Desire filtered output: 01.02 (this number is updated, like in a cURL or pv progress bar)



How can I grep just that part of the output?



So far:




  • The output is sent stderr, like with "Permission denied" from find. An easy way to test (I thought I tried) is to add at the end 2> /dev/null.



    I think the reason why sox/play output to stderr is because it supports writing the output to standard output (stdout) using the special filename - (see sox man page).




  • But |& grep "^In" won't work. Using |& tee log.txt seems uses the delete character to update the last line.



    I tried grep --line-buffered, unbuffer and stdbuf (after readint this and this) with some great progress:



    play -n synth 25:00 pinknoise 2>&1 | stdbuf -oL tr 'r' 'n' | grep -o '[0-9][0-9]*.[0-9][0-9] '


That's very close!



Is possible to get only just one updated line like was on the original output? Maybe like this loop with echo -ne.



I don't know why something like | grep --line-buffered . doesn't work, neither removing trailing newline: | tr -d 'n'. I need something like tail -f -n 1.










share|improve this question




























    2















    It seems a silly situation: I have this command (for pomodoros):



    play -n synth 25:00 pinknoise


    I don't want to silent completely the output (-q option), just one part (the header). grep won't work. I'm not sure how that kind of updated output (like in npm install ... works).



    Normal output:



    File Size: 94.3T 
    Encoding: n/a
    Channels: 1 @ 32-bit
    Samplerate: 48000Hz
    Replaygain: off
    Duration: unknown

    In:0.00% 00:00:01.02 [00:00:00.00] Out:49.2k [======|======] Hd:1.3 Clip:0


    Desire filtered output: 01.02 (this number is updated, like in a cURL or pv progress bar)



    How can I grep just that part of the output?



    So far:




    • The output is sent stderr, like with "Permission denied" from find. An easy way to test (I thought I tried) is to add at the end 2> /dev/null.



      I think the reason why sox/play output to stderr is because it supports writing the output to standard output (stdout) using the special filename - (see sox man page).




    • But |& grep "^In" won't work. Using |& tee log.txt seems uses the delete character to update the last line.



      I tried grep --line-buffered, unbuffer and stdbuf (after readint this and this) with some great progress:



      play -n synth 25:00 pinknoise 2>&1 | stdbuf -oL tr 'r' 'n' | grep -o '[0-9][0-9]*.[0-9][0-9] '


    That's very close!



    Is possible to get only just one updated line like was on the original output? Maybe like this loop with echo -ne.



    I don't know why something like | grep --line-buffered . doesn't work, neither removing trailing newline: | tr -d 'n'. I need something like tail -f -n 1.










    share|improve this question


























      2












      2








      2








      It seems a silly situation: I have this command (for pomodoros):



      play -n synth 25:00 pinknoise


      I don't want to silent completely the output (-q option), just one part (the header). grep won't work. I'm not sure how that kind of updated output (like in npm install ... works).



      Normal output:



      File Size: 94.3T 
      Encoding: n/a
      Channels: 1 @ 32-bit
      Samplerate: 48000Hz
      Replaygain: off
      Duration: unknown

      In:0.00% 00:00:01.02 [00:00:00.00] Out:49.2k [======|======] Hd:1.3 Clip:0


      Desire filtered output: 01.02 (this number is updated, like in a cURL or pv progress bar)



      How can I grep just that part of the output?



      So far:




      • The output is sent stderr, like with "Permission denied" from find. An easy way to test (I thought I tried) is to add at the end 2> /dev/null.



        I think the reason why sox/play output to stderr is because it supports writing the output to standard output (stdout) using the special filename - (see sox man page).




      • But |& grep "^In" won't work. Using |& tee log.txt seems uses the delete character to update the last line.



        I tried grep --line-buffered, unbuffer and stdbuf (after readint this and this) with some great progress:



        play -n synth 25:00 pinknoise 2>&1 | stdbuf -oL tr 'r' 'n' | grep -o '[0-9][0-9]*.[0-9][0-9] '


      That's very close!



      Is possible to get only just one updated line like was on the original output? Maybe like this loop with echo -ne.



      I don't know why something like | grep --line-buffered . doesn't work, neither removing trailing newline: | tr -d 'n'. I need something like tail -f -n 1.










      share|improve this question
















      It seems a silly situation: I have this command (for pomodoros):



      play -n synth 25:00 pinknoise


      I don't want to silent completely the output (-q option), just one part (the header). grep won't work. I'm not sure how that kind of updated output (like in npm install ... works).



      Normal output:



      File Size: 94.3T 
      Encoding: n/a
      Channels: 1 @ 32-bit
      Samplerate: 48000Hz
      Replaygain: off
      Duration: unknown

      In:0.00% 00:00:01.02 [00:00:00.00] Out:49.2k [======|======] Hd:1.3 Clip:0


      Desire filtered output: 01.02 (this number is updated, like in a cURL or pv progress bar)



      How can I grep just that part of the output?



      So far:




      • The output is sent stderr, like with "Permission denied" from find. An easy way to test (I thought I tried) is to add at the end 2> /dev/null.



        I think the reason why sox/play output to stderr is because it supports writing the output to standard output (stdout) using the special filename - (see sox man page).




      • But |& grep "^In" won't work. Using |& tee log.txt seems uses the delete character to update the last line.



        I tried grep --line-buffered, unbuffer and stdbuf (after readint this and this) with some great progress:



        play -n synth 25:00 pinknoise 2>&1 | stdbuf -oL tr 'r' 'n' | grep -o '[0-9][0-9]*.[0-9][0-9] '


      That's very close!



      Is possible to get only just one updated line like was on the original output? Maybe like this loop with echo -ne.



      I don't know why something like | grep --line-buffered . doesn't work, neither removing trailing newline: | tr -d 'n'. I need something like tail -f -n 1.







      command-line bash pipe sox






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 57 mins ago







      Pablo Bianchi

















      asked Mar 3 at 21:20









      Pablo BianchiPablo Bianchi

      2,90521535




      2,90521535




















          1 Answer
          1






          active

          oldest

          votes


















          1














          You can grep the output if you pipe stderr as well, e.g.:





          $ play -n synth 25:00 pinknoise |& grep File
          File Size: 2.52G


          From Pipelines section of GNU Bash manual:




          If ‘|&’ is used, command1’s standard error, in addition to its
          standard output, is connected to command2’s standard input through
          the pipe; it is shorthand for 2>&1 |. This implicit redirection of
          the standard error to the standard output is performed after any
          redirections specified by the command.




          However, this will not work for the progress line: CLI commands usually test whether the output is to a terminal and discard updated output if it isn’t. We need a hacky workaround to get around that. First redirect the full output to a file:



          play -n synth 25:00 pinknoise &>sox.log


          This blocks the current terminal and you can not just send it to the background because then it discards the progress line again. So to get this line, open a second terminal in the same directory and process the file, e.g.:



          $ grep In sox.log
          In:0.00% 00:00:03.24 [00:00:00.00] Out:156k [======|======] Hd:0.8 Clip:0
          $ tail -n+10 sox.log; echo
          In:0.00% 00:00:10.24 [00:00:00.00] Out:492k [!=====|=====!] Hd:1.7 Clip:0


          The advantage of using tail is that you also get the Aborted. line when the play exited:



          $ tail -n+10 sox.log;echo
          In:0.00% 00:00:12.80 [00:00:00.00] Out:614k [======|======] Hd:0.7 Clip:0
          Aborted.





          share|improve this answer

























          • Sorry, this was near but doesn't really work for what I want: get rid of the header so I can only have the line starting with "In:", the one that is updated. I don't know why |& grep "^In" doesn't work.

            – Pablo Bianchi
            Mar 5 at 4:28












          • @PabloBianchi Oh I’m sorry, I misunderstood your question. Could you edit and clarify, maybe giving an example for the desired output?

            – dessert
            Mar 5 at 5:49












          • I added an example of the desired output. Using stdbuf -oL tr 'r' 'n' I'm almost there! Are you sure is necessary to process a file on other terminal? It seems it have something to do with the output buffers.

            – Pablo Bianchi
            Mar 5 at 7:22










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1122816%2fhow-to-pipe-to-grep-play-sox-output%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can grep the output if you pipe stderr as well, e.g.:





          $ play -n synth 25:00 pinknoise |& grep File
          File Size: 2.52G


          From Pipelines section of GNU Bash manual:




          If ‘|&’ is used, command1’s standard error, in addition to its
          standard output, is connected to command2’s standard input through
          the pipe; it is shorthand for 2>&1 |. This implicit redirection of
          the standard error to the standard output is performed after any
          redirections specified by the command.




          However, this will not work for the progress line: CLI commands usually test whether the output is to a terminal and discard updated output if it isn’t. We need a hacky workaround to get around that. First redirect the full output to a file:



          play -n synth 25:00 pinknoise &>sox.log


          This blocks the current terminal and you can not just send it to the background because then it discards the progress line again. So to get this line, open a second terminal in the same directory and process the file, e.g.:



          $ grep In sox.log
          In:0.00% 00:00:03.24 [00:00:00.00] Out:156k [======|======] Hd:0.8 Clip:0
          $ tail -n+10 sox.log; echo
          In:0.00% 00:00:10.24 [00:00:00.00] Out:492k [!=====|=====!] Hd:1.7 Clip:0


          The advantage of using tail is that you also get the Aborted. line when the play exited:



          $ tail -n+10 sox.log;echo
          In:0.00% 00:00:12.80 [00:00:00.00] Out:614k [======|======] Hd:0.7 Clip:0
          Aborted.





          share|improve this answer

























          • Sorry, this was near but doesn't really work for what I want: get rid of the header so I can only have the line starting with "In:", the one that is updated. I don't know why |& grep "^In" doesn't work.

            – Pablo Bianchi
            Mar 5 at 4:28












          • @PabloBianchi Oh I’m sorry, I misunderstood your question. Could you edit and clarify, maybe giving an example for the desired output?

            – dessert
            Mar 5 at 5:49












          • I added an example of the desired output. Using stdbuf -oL tr 'r' 'n' I'm almost there! Are you sure is necessary to process a file on other terminal? It seems it have something to do with the output buffers.

            – Pablo Bianchi
            Mar 5 at 7:22















          1














          You can grep the output if you pipe stderr as well, e.g.:





          $ play -n synth 25:00 pinknoise |& grep File
          File Size: 2.52G


          From Pipelines section of GNU Bash manual:




          If ‘|&’ is used, command1’s standard error, in addition to its
          standard output, is connected to command2’s standard input through
          the pipe; it is shorthand for 2>&1 |. This implicit redirection of
          the standard error to the standard output is performed after any
          redirections specified by the command.




          However, this will not work for the progress line: CLI commands usually test whether the output is to a terminal and discard updated output if it isn’t. We need a hacky workaround to get around that. First redirect the full output to a file:



          play -n synth 25:00 pinknoise &>sox.log


          This blocks the current terminal and you can not just send it to the background because then it discards the progress line again. So to get this line, open a second terminal in the same directory and process the file, e.g.:



          $ grep In sox.log
          In:0.00% 00:00:03.24 [00:00:00.00] Out:156k [======|======] Hd:0.8 Clip:0
          $ tail -n+10 sox.log; echo
          In:0.00% 00:00:10.24 [00:00:00.00] Out:492k [!=====|=====!] Hd:1.7 Clip:0


          The advantage of using tail is that you also get the Aborted. line when the play exited:



          $ tail -n+10 sox.log;echo
          In:0.00% 00:00:12.80 [00:00:00.00] Out:614k [======|======] Hd:0.7 Clip:0
          Aborted.





          share|improve this answer

























          • Sorry, this was near but doesn't really work for what I want: get rid of the header so I can only have the line starting with "In:", the one that is updated. I don't know why |& grep "^In" doesn't work.

            – Pablo Bianchi
            Mar 5 at 4:28












          • @PabloBianchi Oh I’m sorry, I misunderstood your question. Could you edit and clarify, maybe giving an example for the desired output?

            – dessert
            Mar 5 at 5:49












          • I added an example of the desired output. Using stdbuf -oL tr 'r' 'n' I'm almost there! Are you sure is necessary to process a file on other terminal? It seems it have something to do with the output buffers.

            – Pablo Bianchi
            Mar 5 at 7:22













          1












          1








          1







          You can grep the output if you pipe stderr as well, e.g.:





          $ play -n synth 25:00 pinknoise |& grep File
          File Size: 2.52G


          From Pipelines section of GNU Bash manual:




          If ‘|&’ is used, command1’s standard error, in addition to its
          standard output, is connected to command2’s standard input through
          the pipe; it is shorthand for 2>&1 |. This implicit redirection of
          the standard error to the standard output is performed after any
          redirections specified by the command.




          However, this will not work for the progress line: CLI commands usually test whether the output is to a terminal and discard updated output if it isn’t. We need a hacky workaround to get around that. First redirect the full output to a file:



          play -n synth 25:00 pinknoise &>sox.log


          This blocks the current terminal and you can not just send it to the background because then it discards the progress line again. So to get this line, open a second terminal in the same directory and process the file, e.g.:



          $ grep In sox.log
          In:0.00% 00:00:03.24 [00:00:00.00] Out:156k [======|======] Hd:0.8 Clip:0
          $ tail -n+10 sox.log; echo
          In:0.00% 00:00:10.24 [00:00:00.00] Out:492k [!=====|=====!] Hd:1.7 Clip:0


          The advantage of using tail is that you also get the Aborted. line when the play exited:



          $ tail -n+10 sox.log;echo
          In:0.00% 00:00:12.80 [00:00:00.00] Out:614k [======|======] Hd:0.7 Clip:0
          Aborted.





          share|improve this answer















          You can grep the output if you pipe stderr as well, e.g.:





          $ play -n synth 25:00 pinknoise |& grep File
          File Size: 2.52G


          From Pipelines section of GNU Bash manual:




          If ‘|&’ is used, command1’s standard error, in addition to its
          standard output, is connected to command2’s standard input through
          the pipe; it is shorthand for 2>&1 |. This implicit redirection of
          the standard error to the standard output is performed after any
          redirections specified by the command.




          However, this will not work for the progress line: CLI commands usually test whether the output is to a terminal and discard updated output if it isn’t. We need a hacky workaround to get around that. First redirect the full output to a file:



          play -n synth 25:00 pinknoise &>sox.log


          This blocks the current terminal and you can not just send it to the background because then it discards the progress line again. So to get this line, open a second terminal in the same directory and process the file, e.g.:



          $ grep In sox.log
          In:0.00% 00:00:03.24 [00:00:00.00] Out:156k [======|======] Hd:0.8 Clip:0
          $ tail -n+10 sox.log; echo
          In:0.00% 00:00:10.24 [00:00:00.00] Out:492k [!=====|=====!] Hd:1.7 Clip:0


          The advantage of using tail is that you also get the Aborted. line when the play exited:



          $ tail -n+10 sox.log;echo
          In:0.00% 00:00:12.80 [00:00:00.00] Out:614k [======|======] Hd:0.7 Clip:0
          Aborted.






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 5 at 6:25

























          answered Mar 3 at 21:26









          dessertdessert

          24.4k670104




          24.4k670104












          • Sorry, this was near but doesn't really work for what I want: get rid of the header so I can only have the line starting with "In:", the one that is updated. I don't know why |& grep "^In" doesn't work.

            – Pablo Bianchi
            Mar 5 at 4:28












          • @PabloBianchi Oh I’m sorry, I misunderstood your question. Could you edit and clarify, maybe giving an example for the desired output?

            – dessert
            Mar 5 at 5:49












          • I added an example of the desired output. Using stdbuf -oL tr 'r' 'n' I'm almost there! Are you sure is necessary to process a file on other terminal? It seems it have something to do with the output buffers.

            – Pablo Bianchi
            Mar 5 at 7:22

















          • Sorry, this was near but doesn't really work for what I want: get rid of the header so I can only have the line starting with "In:", the one that is updated. I don't know why |& grep "^In" doesn't work.

            – Pablo Bianchi
            Mar 5 at 4:28












          • @PabloBianchi Oh I’m sorry, I misunderstood your question. Could you edit and clarify, maybe giving an example for the desired output?

            – dessert
            Mar 5 at 5:49












          • I added an example of the desired output. Using stdbuf -oL tr 'r' 'n' I'm almost there! Are you sure is necessary to process a file on other terminal? It seems it have something to do with the output buffers.

            – Pablo Bianchi
            Mar 5 at 7:22
















          Sorry, this was near but doesn't really work for what I want: get rid of the header so I can only have the line starting with "In:", the one that is updated. I don't know why |& grep "^In" doesn't work.

          – Pablo Bianchi
          Mar 5 at 4:28






          Sorry, this was near but doesn't really work for what I want: get rid of the header so I can only have the line starting with "In:", the one that is updated. I don't know why |& grep "^In" doesn't work.

          – Pablo Bianchi
          Mar 5 at 4:28














          @PabloBianchi Oh I’m sorry, I misunderstood your question. Could you edit and clarify, maybe giving an example for the desired output?

          – dessert
          Mar 5 at 5:49






          @PabloBianchi Oh I’m sorry, I misunderstood your question. Could you edit and clarify, maybe giving an example for the desired output?

          – dessert
          Mar 5 at 5:49














          I added an example of the desired output. Using stdbuf -oL tr 'r' 'n' I'm almost there! Are you sure is necessary to process a file on other terminal? It seems it have something to do with the output buffers.

          – Pablo Bianchi
          Mar 5 at 7:22





          I added an example of the desired output. Using stdbuf -oL tr 'r' 'n' I'm almost there! Are you sure is necessary to process a file on other terminal? It seems it have something to do with the output buffers.

          – Pablo Bianchi
          Mar 5 at 7:22

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Ask Ubuntu!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1122816%2fhow-to-pipe-to-grep-play-sox-output%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Möglingen Índice Localización Historia Demografía Referencias Enlaces externos Menú de navegación48°53′18″N 9°07′45″E / 48.888333333333, 9.129166666666748°53′18″N 9°07′45″E / 48.888333333333, 9.1291666666667Sitio web oficial Mapa de Möglingen«Gemeinden in Deutschland nach Fläche, Bevölkerung und Postleitzahl am 30.09.2016»Möglingen

          Virtualbox - Configuration error: Querying “UUID” failed (VERR_CFGM_VALUE_NOT_FOUND)“VERR_SUPLIB_WORLD_WRITABLE” error when trying to installing OS in virtualboxVirtual Box Kernel errorFailed to open a seesion for the virtual machineFailed to open a session for the virtual machineUbuntu 14.04 LTS Virtualbox errorcan't use VM VirtualBoxusing virtualboxI can't run Linux-64 Bit on VirtualBoxUnable to insert the virtual optical disk (VBoxguestaddition) in virtual machine for ubuntu server in win 10VirtuaBox in Ubuntu 18.04 Issues with Win10.ISO Installation

          Antonio De Lisio Carrera Referencias Menú de navegación«Caracas: evolución relacional multipleja»«Cuando los gobiernos subestiman a las localidades: L a Iniciativa para la Integración de la Infraestructura Regional Suramericana (IIRSA) en la frontera Colombo-Venezolana»«Maestría en Planificación Integral del Ambiente»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»«Conózcanos»«Caracas: evolución relacional multipleja»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»