Chains the standard streams of a series of commands

learn more… | top users | synonyms

3
votes
5answers
48 views

reading a list of lines from a file writing output to a utility

I have a file with a list of lines I want to read from another file. I want to output those lines to a utility (grep) that lets me read the entire line and pull information from it. The file with the ...
5
votes
2answers
64 views

How can I pipe stdout to another program?

I'm trying to setup a linter for my code and I only want to lint the coffeescript files that have changed in the current branch. So, I generate the list of files using git: git diff --name-only ...
4
votes
0answers
48 views

How come zipping a created disk image, makes smaller files than piping?

Case 1. I use dd to create an image: dd if=/dev/rdiskx of=/path/to/image bs=1m. It's 16 GB in size. I zip it, and it's suddenly around 100 MB. Case 2. I use dd to create an image, piping it ...
5
votes
2answers
67 views

“command | less” vs “less <(command)”

A common "idiom" for viewing large amounts of command output is to pipe it to less, via command | less. However, it's also possible (perhaps only in bash, haven't tested in other shells) to use the ...
3
votes
1answer
23 views

Can close() block?

For example, if you close a pipe or socket that still has data in its write buffer that hasn't been read by the process on the other end, does close() block until the data is read or the other process ...
3
votes
2answers
83 views

Get specific line from command output in awk

I have used pipeline to read specific record from impala shell.Here is what I got [cloudera@localhost ~]$ echo "select * from abc where key > 'a-26052014015400' limit 1;" | impala-shell Starting ...
3
votes
2answers
836 views

Keep global variables values piping through functions

I wrote a little bash script using sed on some html pages to extract some urls. To avoid each time grabbing sed results in a variable then read it again I simply made 3 functions and piped together. ...
7
votes
5answers
173 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?
36
votes
4answers
3k views

In what order do piped commands run?

I've never really thought about how the shell actually executes piped commands. I've always been told that the "stdout of one program gets piped into the stdin of another," as a way of thinking about ...
3
votes
2answers
130 views

using “ifne” in Bash pipe

In my script, I am using the ifne utility from the moreutils package. The line can be simplified to the following: printf "asdf\n" | ifne cat - && echo "stream not empty" ifne only ...
2
votes
1answer
488 views

bottomless tee?

I was just playing around in the terminal and I did this: printf 'some string\n' | { tee /dev/fd/3 | { : && sed 's/some/string/' } } 3>&0 I was really surprised when ...
8
votes
4answers
528 views

Utility to buffer an unbounded amount of data in a pipeline?

Is there a utility that I can stick in a pipeline to decouple read and write speeds? $ producer | buf | consumer Basically, I want a utility buf that reads its input as fast as possible, storing it ...
7
votes
3answers
681 views

Why do some commands not read from their standard input?

I wonder what when we should use pipeline and when we shouldn't. Say for instance, to kill certain process which handling pdf files, the following will not work by using pipeline: ps aux | grep pdf ...
2
votes
2answers
2k views

What's the difference between STDIN and arguments passed to command?

I could use the either form to execute the cat method: cat file_name cat < file_name The result is the same Then I want to execute man in the format of STDIN man < file_name For the ...
2
votes
3answers
14 views

Piping content with multiple spaces

I was attempting to copy files listed in a text file into a directory such as: cat files.txt | xargs -I{} cp "{}" ~/Desktop/temp However I noticed that some files would not copy over. The files ...
14
votes
2answers
1k views

How do I “cat and follow” a file?

A file is being sequentially downloaded by wget. If I start unpacking it with cat myfile.tar.bz2 | tar -xj, it may unpack correctly or fail with "Unexpected EOF", depending on what is faster. How to ...
98
votes
10answers
31k 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 ...
23
votes
3answers
947 views

Should I care about unnecessary cats?

A lot of command-line utilities can take their input either from a pipe or as a filename argument. For long shell scripts, I find starting the chain off with a cat makes it more readable, especially ...
9
votes
2answers
243 views

How a piped shell programs balance their output/input rates? [duplicate]

Possible Duplicate: Bash while loop and reading from pipe I come from web programming background, and find myself interested in one peculiarity of using a local shell. I understand that ...
4
votes
2answers
70 views

continuous reading from named pipe (cat or tail -f)

I have configured rsyslog to log certain log events to /dev/xconsole: *.*;cron.!=info;mail.!=info |/dev/xconsole /dev/xconsole is a named pipe (fifo). If I want to see what is being logged, I ...
6
votes
3answers
2k views

Follow a pipe using less?

Can less follow (by pressing F) a piped input (similarly to a file)? For a file that is being written to, the command less <file> will follow the file when pressing F. But if I have a ...
2
votes
2answers
71 views

Use output from head to copy files with spaces

I have 11 files with spaces in its name in a folder and I want to copy the newest 10. I used ls -t | head -n 10 to get only the newest 10 files. When I want to use the expression in a cp statement I ...
0
votes
1answer
40 views

eval used with piped command

I have file.txt with command stored in one line (this command is valid when running in console) and I want to execute it in one line with sh like cat file.txt | eval what is missing? any protips? ...
2
votes
3answers
60 views

Can I chain pgrep with kill?

I have noticed that | is used to send results of first command to the another. I would like to kill all processes that match a name. This is what pgrep normally does: $ pgrep name 5089 5105 And ...
0
votes
2answers
46 views

How do I sort using the grep and sort command

I would like to create a sorted list of all TCP services found in the file /etc/services. Pipe the output of the command grep tcp /etc/services into the command sort. Redirect the output of this pipe ...
1
vote
1answer
61 views

upstart writing to syslog in a simple way

I have an upstart script that uses pre-start script exec >/dev/kmsg 2>&1 echo starting program # run my program here npm install node app.js end script to redirect output of a ...
6
votes
3answers
257 views

Is it safe to pipe the stdout of A to B in parallel

I'm running A file | B --params > file.txt. Since I want to accelerate the processing speed, I used the parallel -j+0< a.txt to run 20 jobs concurrently. a.txt contains all the commands: A ...
0
votes
1answer
59 views

Pipe output from one command to another command's non standard input [duplicate]

I would like to do something similar to the following: which someapplciation | cd outputfrompreviouscommand The command which provides a directory and I would like to be able to make that output my ...
1
vote
2answers
140 views

readarray (or pipe) issue

I stuck with an strange behaviour of readarray command. The man bash states: readarray Read lines from the standard input into the indexed array variable array but these scripts don't work ...
1
vote
1answer
63 views

Understanding behavior of subshell and stdout with pipe

Let us say I have .c file and corresponding executable (let us say foo) that takes in some input from stdin and then makes a sys call to /bin/sh. Feeding input to this executable like following: ...
1
vote
1answer
57 views

Send copy of a script's output to a file

Say I have a Zsh script and that I would like to let it print output to STDOUT, but also copy (dump) its output to a file in disk. Moreover, the script starts with the following option set -o xtrace ...
3
votes
3answers
112 views

Environment variables are not set when my function is called in a pipeline

I have the following recursive function to set environment variables: function par_set { PAR=$1 VAL=$2 if [ "" != "$1" ] then export ${PAR}=${VAL} echo ${PAR}=${VAL} shift ...
1
vote
1answer
33 views

observing script execution with monit script seems to ignore pipes

I want to have a bash command running in the background and being watched by monit. To get the PID of this process, I found this script on the web and I modified it to fit my commands: (named sdr.sh) ...
2
votes
3answers
6k views

What makes a Unix process die with Broken pipe?

Here are some options I thought of, not sure which is the right one. a) There was an I/O error reading from the pipe. b) The process writing to the other end of the pipe died with a failure. c) All ...
9
votes
1answer
314 views

communication between multiple processes

I have a bash script, which runs manager() function as a separate process for x-times. How is it possible to forward messages to all manager() processes from within the script? I've read about ...
15
votes
5answers
409 views

Is it possible to make zcat output text even if it's uncompressed? [duplicate]

The problem is I have some database dumps which are either compressed or in plain text. There is no difference in file extension etc. Using zcat on uncompressed files produces an error instead of the ...
1
vote
1answer
46 views

Use a bash function in a pipelined command

I have a command similar to: ... | sort -u -V. Since some versions of sort do not support the -V flag, I thought it would be great if I made a function that conditionally adds the flag. But, it seems ...
4
votes
1answer
83 views

Why do bash variables disappear when I use xargs?

I have a simple bash script and want to count how often a command gets called. Here is a minimal example, the counter is called c and should be 4 at the end: #!/bin/bash c=0; for a in X Y; do for ...
2
votes
3answers
90 views

Script needs to read echoed line

So, I need to write a Bourne-shell script, where my script has to work with the line, that was just echoed to stdout - e.g.: echo *something* | myscript.sh [parametres...] This may be a basic ...
29
votes
5answers
7k 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 ...
6
votes
4answers
744 views

Why doesn't grep using pipe work here?

I have the following command: find / -name libGL.so.1 Which returns lots of lines with "Permission denied". I want to exclude such lines, so I added the following: find / -name libGL.so.1 | grep ...
3
votes
5answers
391 views

How can I split a pipe into 16 byte sequences?

I'm writing a bash script to automate the decryption of a certain file; however the file is encrypted in 16 byte blocks, rather than simply encoded in its entirety. Here's some psuedo code to briefly ...
4
votes
2answers
131 views

Running several times the same command with several aguments after a pipe

I have a key (of random binary data) that gets generated by get_key. And with this key, I can do several things with my encrypted files. For example, I can decrypt them. get_key | tee >(decrypt ...
4
votes
3answers
61 views

How to send SIGKILLs to entire pipeline?

while true; do # process substitution instead of usual pipeline to avoid waiting for all programs handle_input_with_timeout < <( prog1 | prog2 | prog3 ) echo "Data stopped flowing. ...
7
votes
3answers
4k views

Redirect stdout over ssh

I would like to run something > file on a remote system through ssh, but if I run ssh host something > file the redirection is executed locally as ssh etc > file I've tried it with ' ...
16
votes
9answers
980 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
1answer
31 views

Limiting readers on a pipe

I want to use a pipe to pass some security credential information from "process1" to another script. I only want authorized reader processes to be permitted to read the pipe. I am thinking I will ...
3
votes
1answer
84 views

Performance differences between pipelines and process substitution

I tend to use pipelines in my bash scripts over process substitution in most situations, especially in cases of using multiple sets of commands as it seems more readable to do ... | ... | ... over ... ...
22
votes
1answer
517 views

How do I redirect command completion output?

On the command line, I can redirect or pipe output of a command to a file or another command using the > or | operator after the command. I have come across a less standard situation that I would ...
1
vote
2answers
136 views

Output of command when piped to another command

I am running a command which does a quick checksum of some file like so find / -type f -ctime +30 -mtime +30 -atime +30 -exec md5sum {} \; | xargs -P 4 and I am trying to run it in parallel with ...