linux - sending output to text file
hope this is an appropriate place to ask this. i have this:
Code:
for file in *.mp3; do sox $file -n stats > $file.txt 2>&1 | tail -1; done thanks, babag |
You could use an append redirection in place of the overwrite which you currently have. Or you could move the redirection to after the 'done' statement.
|
thanks turbocapitalist.
not savvy enough to figure out the append idea. moving the redirect to the end did get it all into one file, though. Code:
for file in *.mp3; do sox $file -n stats; done > stats.txt 2>&1 | tail -1 thanks again, babag |
In the example you have shown, you have redirection from the program into a pipe and then into a file. That last part used > for overwriting instead of >> for appending.
If you wish to add lines, one of the simple ways would be to introduce echo statements: Code:
for file in *.mp3; |
Use ">>" to append the output, instead of ">" to redirect the output. See http://www.linfo.org/output_redirection_operator.html
From the link: Quote:
|
thanks for the replies. i looked at the links and they cleared up a little bit of my confusion but i'm so bad at this that it didn't get me to where i could adapt any of this to work.
i've been continuing to try to get this to work. below is the experience so far. first, this is the output from a single mp3 file as an example of what the txt file i want to create should look like: Code:
DC offset -0.000287 this command, Code:
for file in *.mp3; do sox $file -n stats 2>&1 | tail -1; echo -e '.\n.\n.\n'; done > stats.txt Code:
Window s 0.050 i tried lots of slight variations on this without ever being able to get the output as intended. it seemed like, when i could get the full output from sox into the txt file, i could not get the line breaks so that all of the sox output ran together. whenever i got the line breaks to show up in the text file, the sox output was always truncated to just the last line. thanks again, babag |
spoke too soon. this is starting to get somewhere:
Code:
for file in *.mp3; do sox $file -n stats; echo -e '\n--------------------\n'; done > stats.txt 2>&1 | tail -1 |
think i got it:
Code:
for file in *.mp3; do echo -e '\n--------------------\n' $file '\n'; sox $file -n stats; done > stats.txt 2>&1 | tail -1 Code:
babag |
What is the purpose of tail -1 as the last command? With >stats.txt 2>&1 you're redirecting both stdout and stderr to stats.txt, so tail will never get anything to consume. If you intended to reduce the stderr output to one line then the order of redirections should have been 2>&1 >stats.txt
|
thanks shruggy.
i figured there was probably something extraneous in there and tail seemed a likely place to look but was so relieved to get something to work that i just stopped working on it when i got a good result. just tested without the pipe to tail and it does, indeed, produce the same result. thanks again, babag |
All times are GMT -5. The time now is 07:28 PM. |