Chains the standard streams of a series of commands

learn more… | top users | synonyms

2
votes
3answers
43 views

Redirecting stdout to terminal and file without using a pipe?

I have code, that goes something like this: #!/bin/bash VAR=0 func() { VAR=$((VAR+1)) echo 'Logging information.' } func 2>&1 | tee 'log.txt' echo "Should be 1: ${VAR}" When ...
3
votes
3answers
56 views

source /dev/stdin doesn't work as expected

Let's start with simple tests that work for me to check that source /dev/stdin can be used at all. # echo -ne 'echo a\necho b\n' | source /dev/stdin a b Now I would like to source an actual ...
4
votes
1answer
99 views

cmd2 `cmd1` vs cmd1 | xargs cmd2

I'm trying to find a file with find and then pass the found path to sqlite3. I'm only dropped into the sqlite> prompt if my command is of the form: sqlite3 `find . -type f -iname "*.db" | head ...
0
votes
1answer
14 views

Force ping to write before interrupt

I am trying to get ping to continuously write some times to a file. When I run $ ping 10 10.1.10.28 | perl -ne '/time=(\d+\.\d+)/ && print "$1\n"' It returns one number every several ...
6
votes
4answers
442 views

Back to back Pipes into a Command

Is there a way to pipe back to back values into a command? e.g. If I can command.pl and want to pipe in response, then y to confirm (because it doesn't have a way to auto confirm)? I've tried echo ...
0
votes
1answer
37 views

Using tee or pipe to log console output will cause my program not to start [duplicate]

I'm running hostapd on my raspberry PI to let it function as an accesspoint. It's working fine with the following command: sudo hostapd /etc/hostapd/hostapd.conf This will start hostapd and log all ...
2
votes
1answer
31 views

'Tar' the result of a 'find', preserving the directory structure

I want to tar all the *.txt file, that I get from the result of a find, that exist into a directory having a tree like this: Directory_name dir1 file1.pdf file1.txt dir2 file2.pdf ...
3
votes
1answer
39 views

Problem with getting interactive input in while read loop

I was doing something like the following minimal example: #! /bin/sh # $1 = file containing list of files to sync # $2 = source dir ; $3 = target dir cat "$1" | while read f do cp -i "$2"/"$f" ...
2
votes
2answers
101 views

How to read from a named pipe after the writer process exits?

I want to use named pipes as asynchrnonous task queues (JMS-like, perhaps). For example, suppose a client sends some data that I wish to insert into a database, but I want the client to disconnect ...
2
votes
1answer
32 views

Problems with find, xargs and egrep

I this is what I what I'm trying to end up with (except working) find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii' What am I doing wrong? $ ll total 0 -rw-rw-r-- 1 ...
3
votes
2answers
67 views

Less resource hungry alternative for piping `cat` into gzip for huge files

I have some files of which some are very large (like several GB), which I need to concatenate to one big file and then zip it, so something like this: cat file1 file2 file3 file4 | gzip > ...
1
vote
2answers
101 views

awk - Group by and sum column values

I have command to list system process by memory usage: ps -A --sort -rss -o comm,pmem Which list a table like COMMAND %MEM firefox 28.2 chrome 5.4 compiz 4.8 ...
3
votes
2answers
71 views

How to read user input when using script in pipe

General problem I want to write a script that interacts with the user even though it is in the middle of a chain of pipes. Concrete example Concretely, it takes a file or stdin, displays lines ...
3
votes
2answers
101 views

Bash: cannot break out of piped “while read” loop; process substitution works

I intend to pipe the output of a program into a while read VAR loop and break when a pattern is found, but it doesn't. Proof of concept: inotifywait -qm -e create . | while read line; do echo $line; ...
1
vote
2answers
26 views

Capturing data from a Fluke 1620a via netcat

I am trying to pull temperature and humidity data from Fluke DewK 1620a thermo-hygrometers and write the temp/humidity readings to a log. I can connect to the device via netcat with a simple 'nc ...
2
votes
2answers
49 views

How to pipe a the output of find to another find invocation

Here's what I'm trying to do find . -maxdepth 1 -type d -print0 | xargs -0 -P4 find -name 'war' -type d I would like to create a list of directory names, null-terminated, and then pass this list to ...
1
vote
2answers
75 views

How does Bash pipe large amounts of data?

Let's say you want to cat the contents of a really big file, but want to view it a few bits at a time. Let's say one were to do the following: $ cat /dev/sda1 | less As a programmer of languages ...
1
vote
3answers
32 views

Command that passes its input through to output AND performs command?

I'm trying to use the quote program to make a little shell script that'll keep updating the stock prices every second. quote has to access the Internet and therefore has a small delay when it runs. I ...
1
vote
2answers
62 views

Combination of echo, pipe and cat

I have a file name called temp.csv in my script one of the intermediate step is echo "some info" > final.csv | cat temp.csv >> final.csv at times the file final.csv is created without ...
1
vote
1answer
48 views

Using find -exec and having trouble with redirecting standard error

I have an individual.sh script that pipes standard error to a grep command, like this: FOUND=$(tesseract "$i" out -psm 0 |& grep -ci 'Orientation in degrees: [^0]') If I run the script like ...
2
votes
1answer
31 views

Confused about piping commands from find to commandX?

I have a script, run.sh, that looks like this: #!/bin/bash FILES=$(find corpus/ -type f) for i in $FILES do ./individual.sh $i done It runs without problem. I want to do away with the run ...
1
vote
1answer
55 views

Pipes & redirection binding precedence with disjuncts, conjuncts etc?

I know of the relative binding precedence of operators ‘;’, ‘&’, ‘&&’, or ‘||’ http://www.gnu.org/software/bash/manual/bashref.html#Lists but when pipes come into the picture along with ...
1
vote
0answers
55 views

In adb logcat | grep, how to get the entire original line? [closed]

I am using grep on the Android Logcat to only watch the lines related to my application. My command line is like: adb logcat | grep 'MyAppName' But the results I get is not the original logcat ...
3
votes
1answer
39 views

How to find the file corresponding to a pipe opened by a process? [duplicate]

I created this script, which listens for characters received on a hardcoded pipe, and tries to eval those characters. I call my script loop_executor.sh This is all it contains: !/bin/bash while : do ...
1
vote
1answer
46 views

Redirect output to stdout and pipe to a binary

I have a nice PS1 line in my .bash_profile, and I want to copy it to another machine. So I want to view it AND copy it to my clipboard. I can't figure out how to string the commands to do this ...
2
votes
1answer
85 views

Advantages of using named pipes and sockets rather than temporary files

I have two cooperating programs. One program just writes its output to a file and the other one then reads from the file and spits the data out for the front end to work with. I have been reading ...
3
votes
2answers
129 views

How can a bash script write its standard output from within a pipeline? [duplicate]

I have a bash script that calls a function. The function, amongst other things, executes a pipeline that sinks its output. To simplify it, here is a contrived example: #!/bin/bash func() { ls "$@" ...
1
vote
2answers
49 views

Append a file, output to screen and redirect from stderr all at once, without tee

I'm running a time dd command in a shell script, and I'd like to output the results to a file, and print it out on the screen. The line that I'm currently running is: (time dd of=$dest_filepath ...
5
votes
3answers
261 views

Use bash's read builtin without a while loop

I'm used to bash's builtin read function in while loops, e.g.: echo "0 1 1 1 1 2 2 3" |\ while read A B; do echo $A + $B | bc; done I've been working on some make project, and ...
1
vote
1answer
61 views

Understanding grep and pipes in linux

I came across this post which explains my problem. Suppose there is a file called file.txt which contains "foo World". The answer posted by Tyler explains a lot however I am confused as to how cat ...
0
votes
2answers
280 views

How to redirect stdout & stdin to telnet? [closed]

I am working on embedded product running Linux. The device uses /dev/ttyO0 as console. On boot is automatically start a program with which uses input from /dev/ttyO0 (serial), and gives some ...
4
votes
3answers
87 views

Time required to do pipe output to head/tail [duplicate]

There are lots of txt files in a directory. If I do time wc -l *.txt | head it takes real 0m0.032s user 0m0.020s sys 0m0.008s If I do time wc -l *.txt | tail it takes real 0m0.156s ...
0
votes
4answers
88 views

grep for files and open the resultant matches

I'm trying to open all files based on some return values from grep in the command line. I know that I can use the -l option to only return filenames, but I would like to combine this somehow with ...
0
votes
1answer
83 views

Very basic H/W question using pipe and grep

I have two text files, F1a.txt and F1b.txt, with essentially the same data: the driver's surname and their nationality. For example: Hamilton GBR Alonso SPA I have concatenated these ...
-1
votes
1answer
62 views

Redirect a directory as input to a script and output to a file

I want to use a directory name as a parameter for a pre-made script. Then the output goes into a newly made file in the home directory. It involves pipe/redirection. How do I do that? read dir $dir ...
0
votes
2answers
34 views

Using a file as an input to a script

Say I want to use the name of a file as input, and process it with a pre-made script in a certain directory. How do I do it? fileName < /folder1/scriptName is this the right format?
0
votes
1answer
29 views

Using $BASHPID in grep statement

I'm trying to exclude the PID of the subshell from the results returned by pgrep. Note that the name of the file is the same as the name passed to pgrep. Why does setting a variable equal to BASHPID ...
2
votes
2answers
86 views

redirect output of tee and grep for multiple logfiles

Redirecting output from a script STDOUT + STDERR toLogfile 1 and a grep to Logfile 2 ./run_test.sh 2>&1 | tee -a /var/log/log1.log | (grep 'START|END') > /var/log/myscripts.log How can I ...
5
votes
2answers
263 views

How to capture ordered STDOUT/STDERR and add timestamp/prefixes?

I have explored almost all available similar questions, to no avail. Let me describe the problem in detail: I run some unattended scripts and these can produce standard output and standard error ...
3
votes
1answer
55 views

Make program in a pipe to think it has tty

Test environment: $ mkdir testdir $ cd testdir $ echo | tee "file name" Now, ls will print file?name (under Ubuntu GNU bash, at least), while ls | cat will print file and name in separate lines. ...
0
votes
0answers
36 views

Create tar file which consists of directories from another tar file

I have tar file with three directories, dir1, dir2 and dir3. Is there a way to extract dir2 and dir3 directories to create new tar file on the fly, without extracting the directories in temporary ...
1
vote
2answers
41 views

If I use one of the exec family functions to open a child process, will pipes to parent be applied to the child?

Say I open a parent process with a master process that assigns the stdout to a file for logging. Then say I use the parent process to open a child with execvp (or any other of the exec family of ...
1
vote
2answers
106 views

Concatenate file contents AND names

I've been writing for many months. The files I create are dated files named like 2011-06-13.markdown with daily content. I've decided I want to have all the writing in one file instead but I'd like ...
1
vote
1answer
68 views

Is the data transiting through a pipe confidential?

I read the following question (Shell Script mktemp, what's the best method to create temporary named pipe?) but I'm wondering whether it is preferable to use a temporary named pipe to transfer ...
4
votes
3answers
182 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
381 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
68 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
80 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 ...
0
votes
1answer
105 views

Delete empty directories using 'ls' command

I want to delete empty directories without using find command find . -empty -type d -delete. like the following: if [ "$(ls -d *)" ]; then echo "Not Empty" else echo "Delete" fi How do I ...
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 ...