Chains the standard streams of a series of commands

learn more… | top users | synonyms

1
vote
1answer
60 views

Best way to determine piped command to shell script?

Given tree /some/directory | print.sh Is there any way for print.sh to know that "tree -f /some/directory" was called, without trying to parse pid processes?
1
vote
3answers
8 views

how to pipe the output of cut to the foreach command?

I have the cut command I want that grabs the first word in each line of a file. I then want to put each word from the cut command into a foreach. I then want to do a grep command inside the body of ...
4
votes
1answer
39 views

Does pipe's link target exist somewhere in the filesystem?

I'm talking about this: $ readlink <(echo test) pipe:[80076194] Is pipe:[80076194] a path to the target or just indication that the file descriptor is connected to the pipe and doesn't exist in ...
0
votes
1answer
48 views

Pipe doesn't read my forked script [closed]

I have a problem. I modified a script called 'packer' a AUR-helper for Arch Linux. The problem coming when I apply my pipe, with a progress bar, doesn't show all info as I need. This is my forked ...
17
votes
4answers
630 views

Is there a way to pipe the output of one program into two other programs?

Sorry if this is a silly question but I'm trying to accomplish something like this but on one line: $ prog1 | prog2 $ prog1 | prog3 So, I basically want to execute prog1 and pipe the output to ...
19
votes
5answers
4k views

How to make bidirectional pipe between two programs?

Everyone knows how to make unidirectional pipe between two programs (bind stdout of first one and stdin of second one): first | second. But how to make bidirectional pipe, i.e. cross-bind stdin and ...
2
votes
2answers
33 views

Output of one command is piped to another one; how to close both?

I call Qt Assistant like suggested on stackoverflow: nc -lkU ~/.assistantfifo | assistant -enableRemoteControl & Qt Assistant window is opened, and if I call jobs, it returns: [1] + running ...
83
votes
9answers
25k views

Turn off buffering in pipe

I have a script which calls two commands: long_running_command | print_progress The long_running_command prints a progress but I'm unhappy with it. I'm using print_progress to make it more nice ...
1
vote
1answer
31 views

Pipe chain with devices

As far as I know, you can have the ability to make pipes between applications, such as this one: $ step1 < input_file | step2 | step3 > result_file And you can access devices such as ...
0
votes
2answers
47 views

bash function output to pipe [closed]

I made a bash function to beautify svn output, this function show logs one line per commit, it is great! I like it, but if I use it with pipe it does not work. You can find it on github svn-beautify ...
4
votes
3answers
86 views

How to read user input in pipe?

Let's assume I have a file named confirmation.sh with the following content: #!/bin/bash echo -n "Are you sure [Y/n]? " read line case "$line" in n|N) echo "smth" ;; y|Y) echo "smth" ...
2
votes
2answers
171 views

filter and count with grep in a single pass?

I am using grep at the end of a set of piped commands to filter some rows out of a file. Afterwards I will want to do some arithmetic based on the number of remaining rows. e.g. ...
6
votes
1answer
95 views

bash scripting - read tarball from stdin

I have a task I need to script that I feel should be stupidly simple, but I'm actually having a rather tough time. I have a short bash script that takes a specific type of application in tarball form ...
5
votes
1answer
101 views

Loop through binary data chunks from stdin in Bash

I'm looking for something like while IFS= read -r -n $length str; do ... done but for binary data. Is it possible to do this using dd or other tools? Is there some technique to make these tools able ...
5
votes
4answers
144 views

Can a program next in a pipeline see the exit code of the previous program?

I would like to make a pipeline of Bash scripts like this prog1 | prog2 such that prog2 can see the exit code of prog1 and act differently based on that information. Is this possible?
25
votes
4answers
6k views

Program that passes STDIN to STDOUT with color codes stripped?

I have a command that produces output in color, and I would like to pipe it into a file with the color codes stripped out. Is there a command that works like cat except that it strips color codes? I ...
4
votes
1answer
136 views

Why do piping and redirection work differently with here documents?

Combining a redirect with a here document seems logical enough: $ bash > foo <<EOF echo Hello EOF $ less foo Hello But with a pipe it behaves differently: $ bash | tee foo <<EOF ...
4
votes
5answers
98 views

Semi-asynchronous pipe

Assume I have the following pipe: a | b | c | d How to wait for completion of c (or b) in sh or bash? This means that script d can start any time (and does not need to be waited for) but requires ...
4
votes
4answers
284 views

how do I trim each line in bash?

I would like to remove all leading and trailing spaces and tabs from each line in an output. Is there a simple tool like trim I could pipe my output into?
3
votes
2answers
50 views

Pipe / direct image / video output to foreign server

I am working on a Project that involves taking the output from a Webcam which is in either jpg or h.264 format, and outputting it to a foreign server (HTTP / FTP would work, I am open minded). What is ...
9
votes
2answers
182 views

How can I redirect `time` output and command output to the same pipe?

Suppose I have a binary called foo. If I want to redirect the output of foo to some other process bar, I could write ./foo | bar. On the other hand, if I wanted to time foo, and redirect the output ...
26
votes
4answers
6k views

Can I pipe stdout on one server to stdin on another server?

stdout on one CentOS server needs to be piped to stdin on another CentOS server. Is this possible? Update ScottPack, MikeyB and jofel all have valid answers. I awarded the answer to Scott because, ...
0
votes
1answer
34 views

Piped search queries in vim or less

I would like to be able to search a log file for lines that being with ^2014-02-18 15:30:[0-9:,]* and have UserName:someguy much later in the same line. I am sure I could do a regex to include any ...
3
votes
5answers
336 views

Counting files in folder without wc

Why does the following scripts give a count of 0 instead of giving the count of files present in the directory? #!/bin/bash cd /root/Jamshed/script count=0 ls -lrt > all_files cat all_files | ...
4
votes
3answers
202 views

Please help explain this bash output redirection

This script was posted as answer to a Question. And I'm trying to work out what's going on. result=$( { { ssh host app-status >&3 3>&-; echo "$?" } | { until read ...
1
vote
1answer
108 views

How can I pipe commands to any terminal?

I often use more than one terminal (or terminal emulator) at a time; and while in X I can copy-paste commands, besides not being very practical, it obviously does not work on the real TTY. The first ...
2
votes
2answers
128 views

How to compose bash functions using pipes?

I have few functions defined in this fashion: function f { read and process $1 ... echo $result } I want to compose them together so that invocation would look like f | g | h. What idiom ...
40
votes
12answers
12k views

Get exit status of process that's piped to another

I have two processes foo and bar, connected with a pipe: $ foo | bar bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?
1
vote
3answers
52 views

How to use the pipe command to open a directory after find?

Is there a way to opend found directories (via find) all in one command? One of the things I tried to study several times and never been able to really get, is the effective use of pipe: is it maybe ...
3
votes
2answers
72 views

Repeated commands in a bash pipeline

Sometimes commands repeat in pipeline command. For example (just to illustrate): $ grep -lF 'pattern' ./foo/**/*.bar | xargs dirname | xargs dirname Is there a way to shorten chaining command? For ...
5
votes
3answers
158 views

How to modify output in bash command pipeline

For example, I got from some command some lines $ some-command John Bob Lucy Now I'd like to add chaining command, that modifies output. $ some-command | other-command Hi John Bye Hi Bob Bye Hi ...
16
votes
9answers
831 views

Grep lines but let the first line through [duplicate]

Consider the following output from df. Filesystem Size Used Avail Use% Mounted on /dev/sda1 23G 6.1G 16G 29% / udev 10M 0 10M 0% /dev tmpfs 397M 420K ...
1
vote
2answers
340 views

Why does this ssh command not work? (cat ./file | ssh <user@host> “cat | sudo -t -t 'cat > /root/location/file'”)

I'm trying to do the following but it's not quite right. cat ~/Desktop/blah.png | ssh -t -t trusktr@50.116.4.56 "cat | sudo -i 'cat | /path/to/blah.png'" I have my public ssh key in the ...
3
votes
4answers
74 views

Pipe all input and output of terminal to file

I do not know if this is even possible or not, but in an attempt to keep track of many changes I am about to make to my system I want to track all input I type and all output from a terminal I'm ...
0
votes
4answers
133 views

Why does the command shuf file > file leave an empty file?

I know this is sort of a duplicate of another question (Why this sort command gives me an empty file?) but I wanted to expand on the question in response to the answers given. The command shuf ...
3
votes
1answer
58 views

How can the order of execution in the shell as it relates to redirection be upset about 1 time out of a 1000 on my system? [duplicate]

Considering this Q&A about the order of execution in the shell as it relates to redirection, and despite the fact that if a file doesn't exist it gets created first so that cat example.txt | shuf ...
4
votes
1answer
63 views

Shell one-liner for adding a line in the middle of a pipe

I write a script which sends the input file to CPP, then to grep, then to a certain program: cpp $1 | grep -v "#" | theprogram But, "theprogram" requires the input to start with a certain constant ...
0
votes
2answers
26 views

How can I use tee to print the input stream?

I have a pipe line that looks like this: cat myfile | awk '$3 > 0 { print $1, $2 * $3 }' | tee >(printf) | perl myscript.pl I would like to print the input to my Perl script using tee. How ...
0
votes
0answers
36 views

Postfix mail how to debug transmission to mail handling agent

I have a postfix server running on Ubuntu (and Debian previously). The server is configured to read users and groups from an OpenLDAP server and delivers mail first the spam filter and then to a ...
5
votes
3answers
221 views

Can you pipe to a .bash_profile function?

I received a great function for highlighting files in Apple's finder using the command-line. It's basically a wrapper for osascript. I got it from Mac OS X: How to change the color label of files ...
3
votes
2answers
110 views

grep string from contents of file command then delete file

I have a peculiar problem I need help with. I have a large batch of .docx files where a certain number of them are junk. I know how to identify these files from the file command, as they contain the ...
2
votes
1answer
51 views

Piping periodic data between Python scripts

How to receive data from the environment e.g. bash I am trying to launch two Python scripts in bash and pipe stdout from one of them to stdin of the other. The first script outputs a single ...
2
votes
3answers
110 views

Preserving color output with cut

Using bash interactively I am trying to use cut to prevent the lines from going longer than my terminal width. But when using a command with colorized output all the color gets removed by cut. For ...
0
votes
2answers
94 views

Piping commands together in unix

How do I pipe the output of one command to another in unix? For example, If I want to pipe the output of sort to tail, how would I do that?
1
vote
1answer
37 views

Memory-efficient utility to return N first sorted values

I would like to implement a very popular MapReduce example using only existing programs operating in a UNIX way. The problem is to find N most frequent values in an enormous amount of data. The ...
3
votes
1answer
100 views

Why does grep change the length of output lines?

I often use dpkg or aptitude combined with grep when I want to list certain packages available or installed on my system, but I noticed that when I add | grep, the output lines look a little bit ...
1
vote
5answers
140 views

Pass the output of previous command to next as an argument

I've a command that outputs data to stdout (command1 -p=aaa -v=bbb -i=4). The output line can have the following value: rate (10%) - name: value - 10Kbps I want to grep that output in order to ...
2
votes
2answers
34 views

Piping to the command substitution of a string containing pipes

This works— $ x='grep a' $ echo ab | $x ab This doesn't— $ x='grep a | grep b' $ echo ab | $x grep: |: No such file or directory grep: grep: No such file or directory grep: b: No such file or ...
4
votes
2answers
362 views

How to download an archive and extract it without saving the archive to disk?

I'd like to download, and extract an archive under a given directory. Here is how I've been doing it so far: wget http://downloads.mysql.com/source/dbt2-0.37.50.3.tar.gz tar zxf dbt2-0.37.50.3.tar.gz ...
1
vote
2answers
172 views

Help me understand this echo/spawn/send/expect construct

Here is a line from a bash script I am trying to understand: echo "spawn myscript.sh arg1 arg2; expect \"Please enter your value: \"; send \"myval\r\"; expect eof" | expect I think I understand the ...