tee

Linux write into same file with awk and tee: very odd behaviour

六月ゝ 毕业季﹏ 提交于 2019-12-24 12:07:59
问题 I was trying to do something unusual and overwrite the same file on Unexpected new line when writing out in Unix Shell Script this question just out of curiosity I found that on some attempts I could tee > to_same_file and it worked as you can see on the very first attempt and then subsequent attempts produced an empty file, my assumption is, this must be related to processing time.. Meaning on the first attempt it took longer to get to tee and had time to i/o where as it happens faster on

Redirect a COPY of stdout to different log files multiple times from within same bash script

最后都变了- 提交于 2019-12-22 11:29:31
问题 Following line works well when we want to redirect the stdout to a file, and also get printed on stdout. exec > >(tee logfile-1.txt) However, if we wish to later redirect the stdout to another file, say, exec > >(tee logfile-2.txt) the issue faced is that the output still keeps getting redirected to the first file (logfile-1.txt) along with the second file (logfile-2.txt). Is there a way that the same bash script contains both the statement, and the output be exclusive to each of the files

Is it possible to write a Tee in Windows batch or in Java?

情到浓时终转凉″ 提交于 2019-12-22 09:24:19
问题 I have a Java program that I run in Windows 7 console: java -classpath classfolder mypackage.MyProgram This program runs for very long. Time-by-time it writes output to the console using System.out.println. Is it possible to direct its output both to the console and into a log file in real-time without modifying the existing Java code? If Windows 7 is unable to do that, is it possible to write a Tee utility in Java? Is it solved in Windows 8? 回答1: To do it "without modifying the existing Java

How to redirect stdout+stderr to one file while keeping streams separate?

安稳与你 提交于 2019-12-18 11:26:45
问题 Redirecting stdout+stderr such that both get written to a file while still outputting to stdout is simple enough: cmd 2>&1 | tee output_file But then now both stdout/stderr from cmd are coming on stdout. I'd like to write stdout+stderr to the same file (so ordering is preserved assuming cmd is single threaded) but then still be able to also separately redirect them, something like this: some_magic_tee_variant combined_output cmd > >(command-expecting-stdout) 2> >(command-expecting-stderr) So

How can I compose output streams, so output goes multiple places at once?

浪子不回头ぞ 提交于 2019-12-17 04:02:27
问题 I'd like to compose two (or more) streams into one. My goal is that any output directed to cout , cerr , and clog also be outputted into a file, along with the original stream. (For when things are logged to the console, for example. After closing, I'd like to still be able to go back and view the output.) I was thinking of doing something like this: class stream_compose : public streambuf, private boost::noncopyable { public: // take two streams, save them in stream_holder, // this set their

Capture stdout to a variable but still display it in the console

那年仲夏 提交于 2019-12-17 03:02:42
问题 I have a bash script which calls several long-running processes. I want to capture the output of those calls into variables for processing reasons. However, because these are long running processes, I would like the output of the rsync calls to be displayed in the console in real-time and not after the fact. To this end, I have found a way of doing it but it relies on outputting the text to /dev/stderr. I feel that outputting to /dev/stderr is not a good way of doing things. VAR1=$(for i in

Incorrect results with bash process substitution and tail?

雨燕双飞 提交于 2019-12-12 08:22:09
问题 Using bash process substitution, I want to run two different commands on a file simultaneously. In this example it is not necessary but imagine that "cat /usr/share/dict/words" was a very expensive operation such as uncompressing a 50gb file. cat /usr/share/dict/words | tee >(head -1 > h.txt) >(tail -1 > t.txt) > /dev/null After this command I would expect h.txt to contain the first line of the words file "A", and t.txt to contain the last line of the file "Zyzzogeton". However what actually

Prepend message to rsstail

梦想与她 提交于 2019-12-12 04:54:20
问题 I am trying to prepend a message to the output of rsstail, this is what I have right now: rsstail -o -i 15 --initial 0 http://feeds.bbci.co.uk/news/world/europe/rss.xml | awk -v time=$( date +\[%H:%M:%S_%d/%m/%Y\] ) '{print time,$0}' | tee someFile.txt which should give me the following: [23:46:49_23/10/2014] Title: someTitle After the command I have a | while read line do ... end which never gets called because the above command does not output a single thing. What am I doing wrong? PS: I am

updating a file using tee randomly fails in linux bash script

不想你离开。 提交于 2019-12-12 01:03:19
问题 when using sed -e to update some parameters of a config file and pipe it to | tee (to write the updated content into the file), this randomly breaks and causes the file to be invalid (size 0). In Summary, this code is used for updating parameters: # based on the provided linenumber, add some comments, add the new value, delete old line sed -e "$lineNr a # comments" -e "$lineNr a $newValue" -e "$lineNr d" $myFile | sudo tee $myFile I set up an script which calls this update command 100 times.

Tee with process substitution misunderstanding

不打扰是莪最后的温柔 提交于 2019-12-11 05:12:53
问题 I am trying to write a pretty printer for LDAP entries which only fetches the root LDAP record once and then pipes the output into tee that invokes the pretty printer for each section. For illustration's sake, say my group_entry function returns the LDIF of a specific LDAP DN. The details of which aren't important, so let's say it always returns: dn: cn=foo,dc=example,dc=com cn: foo owner: uid=foo,dc=example,dc=com owner: uid=bar,dc=example,dc=com member: uid=foo,dc=example,dc=com member: uid