Tag Info

Hot answers tagged

24

You could use named pipes (http://linux.die.net/man/1/mkfifo) on the command line of tee and have the commands reading on the named pipes. mkfifo /tmp/data0 /tmp/data1 /tmp/data2 cmd0 < /tmp/data0 & cmd1 < /tmp/data1 & cmd2 < /tmp/data2 & command -option1 -option2 argument | tee /tmp/data0 /tmp/data1 /tmp/data2 When command finishes, ...


14

If I understand correctly, you're looking for the equivalent of tee file1 file2 file3, but rather than write the same data to three files file1, file2 and file3, you want to pipe the same data into three commands cmd1, cmd2 and cmd3, i.e. … | ??? cmd1 cmd2 cmd3 should be equivalent to … | cmd1 & … | cmd2 & … | cmd3 & except that … would ...


13

Do you really want to tar the file or are you looking for downloading a file into a compressed form. Tarring a file is just bundling (uncompressed) files into an (uncompressed) archive. If you want to download a file into a compressed file you can use: wget -qO - <url>|gzip -c - > file.gz


11

Circular I/O Loop Implemented with tail -f This implements a circular I/O loop: $ echo 1 >file $ tail -f file | while read n; do echo $((n+1)); sleep 1; done | tee -a file 2 3 4 5 6 7 [..snip...] This implements the circular input/output loop using the sine algorithm that you mentioned: $ echo 1 >file $ tail -f file | while read n; do echo ...


8

You can't deal with input streams in that way. It is designed to deal with files. If you had managed to create an archive as you describe, what would it look like? How would you untar it? There would be no filename to create, just data. I think your best bet is to get the file and tar it in two separate commands. If you don't want the file to remain on ...


7

How about fold? It's part of coreutils... $ tr -dc 01 < /dev/urandom | fold -w 30 | head -n 5 001010000111110001100101101101 000101110011011100100101111000 111010101011100101010110111001 111011000000000101111110110100 110011010111001110011010100011 Or if that's not available, some flavour of awk: $ tr -dc 01 < /dev/urandom | awk \$0=RT RS=.\{,30} | ...


7

You can use a FIFO for this, created with mkfifo. Note however that its very easy to accidentally create a deadlock. Let me explain that—take your hypothetical "circular" example. You feed a command's output to its input. There are at least two ways this might deadlock: The command has an output buffer. It's partially filled, but hasn't been flushed ...


5

You can try things out with a script such as #!/bin/sh for fd in 0 1 2; do if [ -t $fd ]; then echo $fd is a TTY; fi done Running this I see that: if the script is run on its own, all three FDs are TTYs if the script is run at the start of a pipeline, stdin and stderr are TTYs if the script is run in the middle of a pipeline, stderr is a TTY if the ...


4

At least in bash you can skip mkfifo using process substitution: command -option1 -option2 argument | tee >(cmd1) >(cmd2) >(cmd3) or to adopt Arcege's example tee >(wc -l) >(wc -w) >(wc -c) < /etc/passwd >/dev/null


4

To answer your list of questions by number: Named pipes, a.k.a. fifos, are essentially equivalent to unnamed pipes generated by the shell. The big difference is that synchronization between the two ends is intuitive with the shell version, while named pipes as you seem to be using them require a bit of knowledge about what the shell is doing for you. Yes, ...


4

LC_ALL=C </dev/urandom \ tr '\0-\377' '[0*128][1*]' | dd ibs=50 cbs=10 conv=unblock count=1 That will convert all input ascii bytes (which will be all bytes because LC_ALL=C is specified) into one of either 0 or 1 on an even distribution. The first 128 bytes between \0 and \177 are converted to zeroes and the \200-\377 to ones - and so you get to use ...


4

This is not going to work the way you want it to. A file (obviously with a filename) needs to be stored in the tar. That bit (the filename) is obviously missing if you just pipe the contents of the download to tar. I don't see any way to tell tar that it should pack stdin and specify a filename for that. That said, I really do not say a way to achieve that ...


4

There exists several variants of a watch command, some that spawn a shell to interpret a command line made of the concatenation of the arguments passed to watch (with space characters in between). In those you can do: watch 'ls | shuf' same as: watch ls '|' shuf (those watch actually run: "/bin/sh", ["sh", "-c", "ls | shuf"] and are quite dangerous in ...


3

You will need to store the output in a variable to accomplish this. Here is an example: if output=$(cmda); then printf '%s' "$output" | cmdb fi


3

In the first line, xargs still waits for the second argument or an end of the input. After pressing Ctrl-D xargs continues with the rest and you will see the 5th x as single argument. This example may explain the behavior: (echo "x x x x x"; sleep 5; echo "x") | xargs -n2 Output: x x x x x x # after 5 seconds After the 6th x in the second echo ...


3

The error is because you are redirecting all output to $logfile so there is no output for yad to process. The tool you're looking for is tee: NAME tee - read from standard input and write to standard output and files SYNOPSIS tee [OPTION]... [FILE]... DESCRIPTION Copy standard input to each FILE, and also to standard output. So, you ...


3

In general I would use a Makefile (command make) and try to map your diagram to makefile rules. f1 f2 : f0 command < f0 > f1 2>f2 To have repetitive/cyclic commands, we need to define a iteration policy. With: SHELL=/bin/bash a.out : accumulator cat accumulator <(date) > a.out cp a.out accumulator accumulator: touch ...


3

You know, I'm not convinced you necessarily need a repetitive feedback loop as your diagrams portray, so much as maybe you could use a persistent pipeline between coprocesses. Then again, it may be there isn't too much of a difference - once you open a line on a coprocess you can implement typical style loops just writing information to and reading ...


2

This is similar to a couple of the other answers.  If you have the “moreutils” package, you should have the sponge command.  Try commandA | sponge | { read -r x; { printf "%s\n" "$x"; cat; } | commandB; } The sponge command is basically a pass-through filter (like cat) except that it does not start writing the output until it has read the entire input.  ...


2

find | less When I hit shift+g (go to the end of file in less) HDD starts immediately to work and data starts outputting. Does this mean that when less command has enough data to display it will somehow tell find to not produce further data? No. Pipes work on read()s and write()s. less tells find nothing - but the system kernel which owns that pipe will ...


2

Will tail -100 | sed -n 1p only read one line? No, sed will read 100 lines. If your goal is to read the 100th line from the end of the file, do one of tail -100 | head -1 tail -100 | sed 1q


2

pipeto Unfortunately, rlwrap's built-in filter pipeto does not filter output in the way you desire. I find the documentation rather misleading, but what it does is if you run rlwrap -z pipeto some-shell, then, within the interaction: if you type commands without any pipe sign (|), those are passed verbatim to some-shell and then the output of that is ...


2

bash has both an interactive mode and a batch mode. It enters the corresponding mode depending if stdin is a terminal or not. bash # interactive cat|bash # non-interactive: stdin is a pipe not a terminal cat|bash -i # explicitly request interactive mode In interactive mode bash will print a prompt (configurable by the PS1 variable) and also set ...


2

I'm surprised no one has mentioned the pee command from moreutils (https://joeyh.name/code/moreutils).


2

Your understanding is not quite correct. In a | b the stdout output of process a connected through a pipe to stdin of process b. The problem with your code is that with an additional redirection from somefile to process b you will use two different methods at the same time to connect to stdin of process b. Don't do that! The question is; what do you try to ...


2

You don't say what shell are you using. From the behaviour you are describing it's likely zsh. If you have a look in its man page you would notice how redirections are handled. Note that a pipe is an implicit redirection; thus cat bar | sort <foo is equivalent to cat bar foo | sort (note the order of the inputs). Otherwise, regular ...


1

I found solution: #!/bin/bash mkfifo /etc/z.conf ( while (true) do ssh x@y cat /etc/z.conf > /etc/z.conf done ) &


1

wget -qO - |gzip -c > file_name.gz -c for stdout . that's '>' used. the file get from wget serialize to file_name.gz using standard output library. -qO to send output file


1

then I tried to fill a file with this stream (and end the process of filling by ctrl+c) cat /dev/urandom | tr -dc 01 > foo when I count the numbers of lines of the so created foo file I get 0 lines. cat foo | wc -l 0 Both cat and tr buffer their output. When you press Ctrl+C, any data that's still in either command's buffer is lost. You ...



Only top voted, non community-wiki answers of a minimum length are eligible