Questions tagged [pipe]

A pipe is an interprocess connection between file descriptors of two processes. A pipe is created with the POSIX pipe() function (from ). Shells create pipes between processes if the "|" symbol is used: "cmd1 | cmd2" directs the output of cmd1 to the input of cmd2. On Windows use CreatePipe(). This mechanism redirects standard input, standard output, and standard error into the calling process in .NET and Java.

Every program that runs on the command line has three data streams connected to it: STDIN(0) - standard input, STDOUT (1) - standard output - data printed by the program, STDERR(2) - standard error.

There are ways to connect streams between programs and files called piping and redirections.

Piping is a mechanism for sending data from one program to another using the "|" operator. The operator feeds the output from the program on the left as input to the program on the right.

Example

$ cat two_columns
column1:cloth
column2:strawberries
column3:fish
column4:chocolate
column5:punch cards
$ cat two_columns | awk -F: '{print $1}'
column1
column2
column3
column4
column5 
$ cat two_columns | awk -F: '{print "HAS: " $2}'
HAS: cloth
HAS: strawberries
HAS: fish
HAS: chocolate
HAS: punch cards 

Useful Links

9809 questions
49
votes
9 answers

Get length of .wav from sox output

I need to get the length of a .wav file. Using: sox output.wav -n stat Gives: Samples read: 449718 Length (seconds): 28.107375 Scaled by: 2147483647.0 Maximum amplitude: 0.999969 Minimum amplitude: -0.999969 Midline…
joshu
  • 851
  • 2
  • 9
  • 18
48
votes
8 answers

C# Console receive input with pipe

I know how to program Console application with parameters, example : myProgram.exe param1 param2. My question is, how can I make my program works with |, example : echo "word" | myProgram.exe?
Patrick Desjardins
  • 136,852
  • 88
  • 292
  • 341
47
votes
1 answer

How do I keep colors when piping "jq" output to "less"?

I have a simple json file and if I pipe the output of "jq" into "less", the colors get removed. This works: # yey, lots of colors jq "." /tmp/myfile.json This doesn't work: # ugly output :( , no colors jq "." /tmp/myfile.json | less -R Any ideas…
filipg g
  • 483
  • 1
  • 4
  • 5
47
votes
5 answers

Why no output is shown when using grep twice?

Basically I'm wondering why this doesn't output anything: tail --follow=name file.txt | grep something | grep something_else You can assume that it should produce output I have run another line to confirm cat file.txt | grep something | grep…
radman
  • 17,675
  • 11
  • 42
  • 58
46
votes
1 answer

When to use Pipes vs When to use Shared Memory

I am reading about various IPC mechanism. I am trying to figure out the scenarios, where we use Shared Memory and where we use named Pipes(FIFO). Pipes: Multiple process can Write, however only one process can read. Write operation is atomic. Shared…
vamsi
  • 1,727
  • 3
  • 22
  • 25
46
votes
7 answers

LAMP: How to create .Zip of large files for the user on the fly, without disk/CPU thrashing

Often a web service needs to zip up several large files for download by the client. The most obvious way to do this is to create a temporary zip file, then either echo it to the user or save it to disk and redirect (deleting it some time in the…
Benji XVI
  • 2,192
  • 1
  • 25
  • 24
46
votes
9 answers

Is it safe to pipe the output of several parallel processes to one file using >>?

I'm scraping data from the web, and I have several processes of my scraper running in parallel. I want the output of each of these processes to end up in the same file. As long as lines of text remain intact and don't get mixed up with each other,…
conradlee
  • 12,985
  • 17
  • 57
  • 93
46
votes
7 answers

How to make a bash function which can read from standard input?

I have some scripts that work with parameters, they work just fine but i would like them to be able to read from stdin, from a pipe for example, an example, suppose this is called read: #!/bin/bash function read() { echo $* } read $* Now this…
JBoy
  • 5,398
  • 13
  • 61
  • 101
44
votes
5 answers

How to use pipe in ts not HTML

I adding text into html element from ts like this this.legend.append('text') .attr('x', legendRectSize + legendSpacing) .attr('y', legendRectSize - legendSpacing) .text(function(d) { return d; }); this will create html like Data will…
Arun Tyagi
  • 2,206
  • 5
  • 24
  • 37
44
votes
3 answers

Why should you close a pipe in linux?

When using a pipe for process-process communication, what is the purpose of closing one end of the pipe? For example: How to send a simple string between two programs using pipes? Notice that one side of the pipe is closed in the child and parent…
pghazanfari
  • 515
  • 2
  • 6
  • 8
43
votes
5 answers

Piping and Redirection

What is exact difference between piping and redirection? Where should we use piping and where should we use redirection? How they internally work?
Vikram
  • 1,999
  • 3
  • 23
  • 35
43
votes
3 answers

Getting output from a shell/dos app into a Delphi app

I have a commandline application coded in delphi that I need to call from a normal desktop application (also coded in delphi). In short, I want to call the commandline app and display the text it outputs "live" in a listbox. It's been ages since I…
Jon Lennart Aasenden
  • 3,920
  • 2
  • 29
  • 44
43
votes
2 answers

bash command preserve color when piping

Possible Duplicate: Can colorized output be captured via shell redirect? setup In this case specifically I'm trying to preserve the colors in git status -s when piping it to another command. Some git commands, diff for instance, and other…
rennat
  • 2,529
  • 3
  • 26
  • 30
43
votes
11 answers

Angular - Type Pipe does not have 'ɵmod' property

I am attempting to create a custom pipe that would return a sum of an array in a table, but for whatever reason, Angular is complaining about my pipe not having an 'emod' property. My pipe: import { Injectable, Pipe, PipeTransform } from…
TheDoomDestroyer
  • 2,434
  • 4
  • 24
  • 45
42
votes
8 answers

Angular2 date pipe does not work in IE 11 and edge 13/14

I'm using Angular 2.0 final, and I have an incorrect format of dates when I add hours and minutes in the format string: In the template of the component, I have: {{dto.LastExecution | date:'yyyy-MM-dd HH:mm:ss'}} The…
Anthony Brenelière
  • 60,646
  • 14
  • 46
  • 58