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
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 end2> /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
andstdbuf
(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
add a comment |
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 end2> /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
andstdbuf
(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
add a comment |
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 end2> /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
andstdbuf
(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
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 end2> /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
andstdbuf
(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
command-line bash pipe sox
edited 57 mins ago
Pablo Bianchi
asked Mar 3 at 21:20
Pablo BianchiPablo Bianchi
2,90521535
2,90521535
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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 for2>&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.
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. Usingstdbuf -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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 for2>&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.
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. Usingstdbuf -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
add a comment |
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 for2>&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.
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. Usingstdbuf -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
add a comment |
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 for2>&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.
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 for2>&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.
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. Usingstdbuf -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
add a comment |
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. Usingstdbuf -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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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