Chains the standard streams of a series of commands

learn more… | top users | synonyms

4
votes
3answers
119 views

Get PID of any command in backgrounded piped sequence of commands

If, in bash, I execute: cmd1 | cmd2 | ... | cmdi | ... | cmdn & where the cmd{1..n} may not be distinct, how do I get the PID of cmdi? Alternatively, how can I signal the cmdi process? (For ...
5
votes
2answers
144 views

Why does process substitution result in a file called /dev/fd/63 which is a pipe?

I am trying to understand named pipes in the context of this particular example. I type <(ls -l) in my terminal and get the output as, bash: /dev/fd/63: Permission denied. If I type cat <(ls ...
2
votes
2answers
49 views

Should I use piping or redirection for input to 'sort'

I want to do awk -F "," '{print $1 }' inputfile1.txt | sort -u > distinctOutput.txt Is this good performance-wise ? Or should I redirect / use a temp file since I think it is better to make sort ...
1
vote
1answer
72 views

What is happening while executing this command cd / | vi?

When I execute the command cd / | vi, it goes to the vi editor. When I type any command it does not display the command but it gets executed and the command that is executed is not shown in the ...
-2
votes
1answer
42 views

Delete empty directories without find

I want to delete empty directories without using find command like the following: Instead of find . -empty -type d -delete use if [ "$(ls -d *)" ]; then echo "Not Empty" else echo "Delete" fi ...
26
votes
4answers
2k views

Why does “tail -f … | tail” fail to produce any output?

Why does the following command not produce any output? $ tail -f /etc/passwd | tail After reading about buffering, I tried the following to no avail: $ tail -f /etc/passwd | stdbuf -oL tail Note ...
2
votes
0answers
21 views

Close All Piped Commands if one close

I'm running at least 3 commands (with progs) using pipes. For example program1 bla bla | program2 blabla | program3 bla bla Is possible to close all programX PIDS automatically if at least one ...
1
vote
0answers
30 views

Verbose output in logfile and simple output on screen?

Let's say I have the following script: script.sh and i want the verbose output in a logfile and simple output on screen. Logfile should contain the csh -v script.sh output, and on the screen should ...
2
votes
1answer
45 views

How can I pipe the output of a program or function into a variable?

How can I pipe the output of a program or function into a variable? For example lets say I have this script: function foobarize () { sed \ -e "s|${foo}|${bar}|g" \ $1 } echo foo | ...
5
votes
2answers
105 views

How do I preserve coloured output when piping to `less -R`?

$ ffmpeg -v debug ... Coloured output. $ ffmpeg -v debug ... |& less -R Dull output. How do I make the output coloured while piping it to something?
3
votes
2answers
39 views

Problem with read variable from AWK

I'm trying to get memory info by this command: #!/bin/bash set -x cat /proc/meminfo | grep "MemFree" | tail -n 1 | awk '{ print $2 $4 }' | read numA numB echo $numA I'm getting this + awk '{ print ...
2
votes
1answer
39 views

Why doesn't PIPESTATUS work on pipelines within a command substitution

Proof below: Bash 4 Prompt> $(echo hello|sed 's/h/m/'|xargs -I{} ls {} 2>/dev/null|sed 's/ /_/') Prompt> for i in ${PIPESTATUS[@]}; do echo $i;done Output> 0 Prompt> echo hello|sed ...
3
votes
4answers
166 views

Redirect and pipe output

rpm -qa > file | wc -l returns 0. What am I doing wrong? I think it is clear what my goal is, but it isn't working. Is this a job for xargs or tee?
1
vote
3answers
32 views

How can I pipe data over network or serial to the display of another linux machine?

I have a second monitor that I'd like to use for a text-based debugging log and/or console. I don't want to have it as part of my GUI / "desktop" / main system. I have this display connected to an ...
1
vote
1answer
63 views

Why doesn't this piped script work?

#!/bin/bash rm out mkfifo out nc -l 8080 < out | while read line do echo hello > out echo $line done If I browse to the IP of the machine this script is running on (using port ...
4
votes
1answer
65 views

unexpected output with grep

I am using pyrit. For those who dont know, pyrit allows among other things to check if a wpa handshake key is valid: pyrit -r file0.cap analyze when a file does not contain a valid key, here is ...
1
vote
1answer
155 views

Why are these values not appending correctly when appended to the pipeline? [duplicate]

I have a bash script (seen here) that I'm using to sort a list of files in subdirectories by filename. This script appends sorted files in hooks/pre-relevant/, then files named hooks/pre-relevant, ...
2
votes
1answer
43 views

Is there a system call to bind a file descriptor directly into another?

A read() & write() loop would probably be as good as what I'm looking for, but nevertheless is anything like that around or is it impossible because of an obstacle I didn't envisage ? I'm curious
8
votes
2answers
299 views

check md5sum from pipe

I am confused how md5sum --check is supposed to work: $ man md5sum -c, --check read MD5 sums from the FILEs and check them I have a file, I can pipe it to md5sum: $ cat file | md5sum ...
1
vote
1answer
21 views

What standard shell command can evaluate escaped Unicode in a stream?

I'm looking for a pipeable command that will convert substrings in the form of ‘\unnnn’ to the actual characters. For example: $ echo 'co\u00ebfficient' | what_command coëfficient
7
votes
1answer
482 views

How pipes work in Linux

I've been reading up about how pipes are implemented in the Linux kernel and wanted to validate my understanding. If I'm incorrect, the answer with the correct explanation will be selected. Linux ...
1
vote
0answers
16 views

Test execution output of a command before a pipe [duplicate]

I would like to test the execution of a php script that redirect its stdout and stderr to a file with tee. php /path/to/script --param 2>&1 | tee -a /path/to/log if ( test $? -ne 0 ); then ...
4
votes
0answers
65 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
83 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 ...
4
votes
6answers
118 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
82 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 ...
3
votes
1answer
27 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 ...
4
votes
2answers
144 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
168 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 ...
7
votes
3answers
762 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
3answers
23 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 ...
4
votes
2answers
243 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 ...
2
votes
2answers
112 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
52 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? ...
0
votes
2answers
287 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 ...
2
votes
3answers
95 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 ...
2
votes
1answer
494 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 ...
1
vote
1answer
130 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 ...
0
votes
1answer
142 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 ...
6
votes
3answers
263 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 ...
1
vote
2answers
321 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
132 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: ...
4
votes
3answers
194 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
115 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 ...
9
votes
1answer
354 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
482 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
98 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
98 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 ...