Linked Questions

1 vote
3 answers
2k views

Pipe output of one command to two others [duplicate]

I need to pipe the output of one command to two other commands. cat filename.txt | tail -n 1 cat filename.txt | wc -l Since the file is huge I want to avoid reading it twice. I checked tee command ...
chhaya vishwakarma's user avatar
1 vote
2 answers
2k views

Run command once and filter output in multiple files [duplicate]

Is there anyway to redirect filtered output to multiple files by running mycommand.sh only once? Example output should be similar to this: mycommand.sh | grep --line-buffered -B 1 A >> file1 ; ...
Future's user avatar
  • 179
1 vote
2 answers
396 views

Combine command output along with the input [duplicate]

I'd like to print command output along with its input. For example for such call as echo "Hello world" | wc -c I want the following output: 12,Hello world Is there any way to do this using ...
Petr Razumov's user avatar
106 votes
9 answers
70k views

When would you use an additional file descriptor?

I know you can create a file descriptor and redirect output to it. e.g. exec 3<> /tmp/foo # open fd 3. echo a >&3 # write to it exec 3>&- # close fd 3. But you can do the same ...
dogbane's user avatar
  • 30.1k
31 votes
6 answers
11k views

Pipe to multiple files in the shell

I have an application which will produce a large amount of data which I do not wish to store onto the disk. The application mostly outputs data which I do not wish to use, but a set of useful ...
sj755's user avatar
  • 1,135
61 votes
3 answers
11k views

What is the portable (POSIX) way to achieve process substitution?

Some shells, like bash, support Process Substitution which is a way to present process output as a file, like this: $ diff <(sort file1) <(sort file2) However, this construct isn't POSIX and, ...
starfry's user avatar
  • 7,530
10 votes
4 answers
10k views

Command redirection to multiple files: command >file1 >file2

I have this command: cat somefile >file1 >file2 After I executed this command I can't figure out why file1 has nothing in it. It should have the output of the first file (somefile), but ...
Charlie Albert's user avatar
5 votes
5 answers
1k views

evaluate multiple patterns from program output and write into pattern specific files

I have a script outputting some value/numbers and I want to split those into two files. I am looking at something like: ./runme.sh | grep 'ook' >> ook.out | grep 'eek' >> eek.out Where ...
Sardathrion - against SE abuse's user avatar
4 votes
1 answer
6k views

How to pipe a command output to multiple programs

I'm using FFmpeg and I have made a custom application which is a TCP server. I 'm using duplicate output in ffmpeg. What I want is, for each output I want to start my program to listen on a specific ...
user3393046's user avatar
2 votes
2 answers
6k views

how to move (not copy) files from one server to another?

I want to move files from server1 to server2. A producer on server1 will keep generating the files, and a consumer on server2 will keep processing them. I can copy files using the following shell ...
atripathi's user avatar
  • 295
4 votes
1 answer
3k views

How to read from stdin in process substitution? [duplicate]

I would like to send stdout to multiple commands, however I'm not sure how do I read from standard input within process substitution? My attempts: $ echo foo >(cat /dev/stdin) >(cat /dev/stdin)...
kenorb's user avatar
  • 21.5k
3 votes
1 answer
4k views

Write data to both a file and a serial port — can I use tee?

I am trying to take the input from a serial port and write it to a file and also then read the file and send it back out the serial port to the host computer. A coworker suggested using the "tee" ...
Julien's user avatar
  • 31
6 votes
2 answers
2k views

dash: Pipe STDIN to multiple commands and their output to STDOUT in defined order

At first I thought this answer was the solution, but now I think I need a temporary file as buffer. This works unreliably: #!/bin/sh echo 'OK' | { { tee /dev/fd/3 | head --bytes=1 >&...
Kontrollfreak's user avatar
1 vote
1 answer
808 views

Redirect back to stderr in shell

Somewhat re-asking my question since I mistakenly asked in SO with a bash shell tag and figured this is a more appropriate place. I'm writing a shell script within AWS DataPipeline that connects to a ...
simplycoding's user avatar
1 vote
1 answer
2k views

Piping to multiple awk commands

I'm trying to pipe the output of one command to two different awk commands. Following this post I am using tee and process substitution. However, I can't see the output for the substituted process. ...
ludog's user avatar
  • 17

15 30 50 per page