Tag Info

New answers tagged

1

echo -e "Hello \nWorld \n" >> greetings.txt


6

With socat (version 2 or above): socat 'system:cat input.txt & cat > output.txt,commtype=socketpair' \ 'system:foo,nofork' Or even better: socat 'CREATE:output.txt%OPEN:input.txt' 'system:foo,commtype=socketpair' We're using a socketpair which is bidirectional (pipes are not bidirectional on Linux). Another option is to use a ...


2

cat /dev/null is a no op as it outputs exactly nothing. A simpler way to blank a file's content is then to redirect the null command to it that way: : > file or even, with most shells, only use a redirection without specifying any command: > file The fact the reported size by ls is still high is just due by the writing process seeking to the ...


3

Assuming you meant to say cat /dev/null > file_log.txt the answer is that the process that has the file open for writing did so without O_APPEND, or it sets the offset into the file arbitrarily, in which case a sparse file is created. This is a file that contains "holes", i.e. the system "knows" that there are large regions with zeroes, which are not ...


2

cat /dev/null file_log.txt This only made cat read /dev/null and immediately read file_log.txt and output the result to stdout, your screen. This won't delete anything, at all. If you want to test out, use cat /dev/null non_existent_file and you will see that it errors out. The correct way to truncate a file, is using shell redirectors or any kind of ...


4

Isn't cat reading from the stdin and stores that that into file "filename"? Yes, when cat does not have any filename arguments (or if one of the files is the minus character -), it reads from stdin. Perhaps use of the word "never" by the book is a bit misleading, because: Is the above excerpt from the book just saying that only the particular form ...


2

What is it you are missing? You seem to have understood everything. The > file sends the output to file and 2>&1 sends standard error to standard output. The final result is that both stderr and stdout are sent to file. To illustrate, consider this simple Perl script: #!/usr/bin/env perl print STDERR "Standard Error\n"; print STDOUT "Standard ...


5

You just have to read it left to right: > file --> redirect all thing from stdout to file.(You can imagine you have a link, point-to-point from stdout to file) 2>&1 --> redirect all thing from stderr to stdout, which is now pointed to file. So conclusion: stderr --> stdout --> file You can see a good reference here.


2

the file's content is shown as empty as long as the file is opened for writing by Bash. That's not exactly what's happening. What's happening is that the task buffers its output — it is accumulated in memory for a while, then written to the file in chunks. The in-memory buffer has a fixed size of a few kilobytes. This is done for performance, as each ...


2

Take a look at tee command, here are some examples with it. The following command (with the help of tee command) writes the output both to the screen (stdout) and to the file. $ ls | tee file


1

It seems applying a command line argument to a bsub file is a very complicated process. I tried the HEREDOC method stated by mikeserv, but bsub acted as if the script filename was a command. So the easiest way to get around this problem is just to not use input redirection at all. Since my question specifically involved bsub for Platform LSF, the following ...


0

You need either a here document or a here string. bsub <<HEREDOC $(script.bsub 1) HEREDOC That's what a here document looks like. The shell will read in the expansion of everything between the line in which <<HEREDOC occurs until it finds a line on which nothing but HEREDOC occurs and pass the output to the invoked command on its file ...


3

So, it looks like gradle run doesn't comply with tee, pee, grep and io-redirection. It always stops reading after 4096 bytes. To circumvent this issue, I read each line of gradle run. I didn't test it yet, but I guess that reading a line that is over 4k characters long will also fail. Anyway, here is the code to solve my question specifically: #!/bin/bash ...


7

In Bash, you can use process substitution with tee: tee >(grep XXX > err.log) | grep -v XXX > all.log This will put all lines matching XXX into err.log, and all lines into all.log. >( ... ) creates the process in the parentheses and connects its standard output to a pipe. This works in zsh and other modern shells too. You can also use the pee ...


5

The usual solution to this problem is to put your time command in a group: $ { time wc test >wc.out; } 2>time.out


1

Use a shell function xyx () { cat "$1".$2 > "$1".$3; } then xyz fie foo fum expands to cat fee.foo > fee.fum


9

You can type: $ cat very-long-filename.ext1Ctrl+WCtrl+Y>Ctrl+YBackspace2 Or: $ cat very-long-filename.Ctrl+WCtrl+Yext1>Ctrl+Yext2 To really use brace expansion, note that: cat a.ext1 > a.ext2 Can also be written: cat > a.ext2 a.ext1 However you cannot do: cat > a.ext{2,1} However, you could do: eval cat \> a.ext{2,1}


2

What about:- f=really-long-filename; cat "$f.ext1" > "$f.ext2"



Top 50 recent answers are included