1
vote
3answers
57 views

Pass stdin to multiple programs without closing

I want to split and GZip a large file, and this answer appeared to be what I'm looking for, and it seemed like a very useful way of doing things I never thought of, so I'd like to generalize it; the ...
5
votes
2answers
345 views

How to a open a file in vim using pipe

I get to use the locate command extremely often. So if I run the following command. locate updatedb | head -1 Then it gives me the O/p /usr/updatedb.conf I wonder if there is any such command ...
1
vote
1answer
29 views

Pipeing lines to repeat commands

If my grep operation returns a list of ID's like: 12345 84758 49549 .. can I somehow feed/pipe each line to a commandline command's parameter? Like for example with the above result from grep, I'd ...
1
vote
1answer
66 views

How to parse pipe with multiple commands independently?

How can I parse output of a single command by multiple commands without truncating at each step? For example ls -al|grep -i something will pass every line that has "something" in it to the next ...
8
votes
5answers
1k views

What does the linux pipe symbol “|” do? [duplicate]

Here is a command that sorts files in a folder in reverse order ls | sort -r What does the | symbol in that command do? What I'm really looking for here is high level (easy to understand) ...
0
votes
1answer
38 views

Bash: multiple commands with pipe on 1 line

This command gets my ip address: who am i|cut -d "(" -f2 | cut -d ")" -f1 output: 10.22.184.126 this command sends a ZPL command to 10.22.184.126 on port 5964: printf ...
0
votes
1answer
69 views

Bash alias with Sed not working

Does anyone know why this alias isn't working? alias tailsed="tailf error.log | sed -e 's/\\n/\n/g' -e 's/\\t/''/g'" I've tried replacing the single quotes with doubles so that it's like: alias ...
0
votes
0answers
39 views

redirect tar notices when used with pipe

I have a remote backup cron script that contains the following line: cat ${list} | xargs tar Jlcf - | ssh -i /root/.ssh/backup \ seron@dummy.net "backup_${DATE}.txz" It gives tar a list of ...
2
votes
1answer
447 views

Is there a way around broken pipe?

I have a directory with a large number of files. ./I_am_a_dir_with_many_subdirs/ Within a script I'd like to find all subdirs in it, to sort them and to output to a bash array. So, I do: ...
0
votes
2answers
106 views

Pipe core dumps from script

I am making a testing script to compile (via make) and run a bunch of tests. I have a series of cat, grep and sed commands that organizes the results of all the tests nicely, however core-dumps are ...
3
votes
2answers
283 views

How do I pipe output to date -d “value”?

I have a date like "2014-01-30 05:04:27 GMT", and if I run date -d "2014-01-30 05:04:27 GMT", the output is in my server's timezone ("Thu Jan 30 16:04:27 EST 2014"). With the use of grep and cut, I ...
1
vote
2answers
269 views

How do you use PIPESTATUS, tee and /bin/sh together?

When I run curl | tee test.txt; echo ${PIPESTATUS[0]} I correctly see curl: try 'curl --help' or 'curl --manual' for more information 2 But when I try to run exactly same command using ...
1
vote
1answer
191 views

Programs detecting pipe on its output to disable coloration

Some programs have a colored output (such as grep or emerge on my gentoo system), but if their output is piped, into less for example or into a file, the colored output is disabled. Yet, I know less ...
4
votes
2answers
69 views

Sort files with grep

I have a few hundreds of output files, of which some contain error messages. Lets say I want to automatically put all files containing the string "ERROR_1" in a "subfolder_1", and the rest in a second ...
0
votes
2answers
264 views

Format data as a table in bash

I have an array of JSON data being printed to the terminal (OS X) and I want the properties of that to be displayed in a table in the terminal. Sample query: aws ec2 describe-instances | jq '[ ...
0
votes
1answer
237 views

Streaming log file contents (piping)

I am trying to understand how piping works and am stuck at this point. A log file is being streamed and its output is being piped to pigz. What I am trying to do is, redirect the pigz content to a ...
1
vote
1answer
196 views

Why the here-strings in bash are slower than piping the input to a command?

I compared the execution time for unix here-strings and pipe data input to bc: pipe time for i in {1..1000} do echo "sqrt(5.09)" | bc -q > /dev/null done real 0m3.584s user ...
3
votes
2answers
368 views

Why is xargs necessary?

Suppose I want to remove all files in a directory except for one named "notes.txt". I would do this with the pipeline, ls | grep -v "notes.txt" | xargs rm. Why do I need xargs if the output of the ...
1
vote
1answer
311 views

grep with colored output returns several empty lines

I have strange issue with grep (2.12-2, debian testing). In some situations when I do something like this: grep -rni '."spacer">.' . grep return me several empty lines: If I add --color=none ...
1
vote
2answers
86 views

Finding folders only

My harddrive is in a mess, so I decided to do a cleanup. As a part of this, I want to merge all folders containing music into one. What I want to do is, look for any *.mp3's and *.aac's on my drive ...
0
votes
1answer
341 views

Reading the same stdin with two commands in bash

I would like to pipe an output of to two separate commands <2,3> in bash. What is the best way of doing this? At the moment, I have following script: command source > output command2 output ...
1
vote
1answer
265 views

Alias defined in .bashrc not working after pipe

I'm stuck with the following problem. I've defined an alias in .bashrc (and .bash_profile): alias echo2="echo" This works well: $ echo2 "test" test However, if I try to use it after a redirect, ...
2
votes
1answer
1k views

How to redirect multiple bash commands to a variable AND screen?

I would like to capture a subshell's output in a variable and print it in the terminal screen simultaneously. Is it possible to do this by assigning the subshell to a variable and piping stdout and ...
4
votes
3answers
122 views

Transparent usage of temporary files as means of piping

As many of us are surely aware, it's always a good idea to make your program accept stdin input. Very many programs do allow that *nix environments. This lets us do cool things like piping echo "foo" ...
2
votes
3answers
268 views

How do I make a bash alias that outputs file names in a format I can pipe to vim?

When rebasing with git, I'm interested to open the files that have merge conflicts. I can do this with: vi `git diff --name-status --diff-filter=U | awk '{print $2}'` but if I alias that: alias ...
3
votes
1answer
218 views

Redirect stdout to multiple programs

I'm doing some stream processing of some quite substantial files-- I was wondering if there was a way to split stdout in order to pipe to multiple programs. What I'd like to do is something like this: ...
4
votes
5answers
295 views

How do I pipe a list of numbers straight from the shell into a command?

How do I pipe a list of numbers straight from the shell into a command? For exampe something like this [1,2,3,4] | sort would give 1 2 3 4 EDIT: In response to the answers kindly posted so ...
0
votes
2answers
201 views

Why cat $(find /usr/portage -name *.ebuild) | grep RESTRICT - works? And find | grep - not?

Why I can't grep find? Only helps grepping cat of find. As I see program grep could see some context in which every command runs. But it's counterintuitive for a newbie like me. When given with ...
2
votes
2answers
700 views

Piping bash output to perl script's arguments

I have the following bash command: find repo -name '*.c' What I want to do is use the files returned as arguments to my perl script, so that it's equivalent to running: perl ./myscript file1.c ...
2
votes
3answers
693 views

count files in a list of directories

I have file with a list of directories that I would like to know how many files are in each directory. .../images/idsuffix/userids/ This will give me the count of files and directories for ...
4
votes
3answers
3k views

Can I use pipe output as a shell script argument?

Suppose I have a bash shell script called Myscript.sh that need on argument as input. But I want the content of the text file called text.txt to be that argument. I have tried this but it does not ...
1
vote
2answers
523 views

Bash: Concatenating TAR balls

Is it valid to do this: { tar -c dir1 tar -c dir2 } | cat > file.tar Is the resulting file.tar a valid tar ball? If not, how can I concatenate tar balls on the fly?
6
votes
5answers
3k views

How to get both PIPESTATUS and output in bash script

I'm trying to get last modification date of a file with this command TM_LOCAL=`ls -l --time-style=long-iso ~/.vimrc | awk '{ print $6" "$7 }'` TM_LOCAL has value like "2012-05-16 23:18" after ...
1
vote
2answers
1k views

How can I clear the contents of every file in a subdirectory without changing ownership / permissions?

I can find the list of files using something like: find /path/to/files -type f And I can clear the contents of a single file with any of: > filename echo -n > filename cat /dev/null > ...
1
vote
3answers
175 views

Piping file to a command that doesn't implement piping

$ cat foo foo bar Now if I do: $ some_program foo It's working. But if I try: $ cat foo | some_program It's not working. I'm looking for a clean way to pipe input to some_program without ...
1
vote
1answer
158 views

redirecting output from several piped commands

This works: find . -type f | xargs md5sum | sort This does not and gives several "md5sum: xyz not found" errors: ( find . -type f | xargs md5sum | sort ) >~/md5.txt Same for: find . -type f ...
1
vote
4answers
1k views

less emulate a TTY to preserve piped color output

When you pipe something through less, the program usually discards color codes because it's not outputting to a TTY. So you have to add --color=always to the options for it to work. ls -l ...
2
votes
1answer
218 views

how to convert a script using pipelines to named pipes

I have a bash script that is using anonymous pipes to achieve: grabbing video from dv capture device writing to a file (using tee) piping it to ffmpeg2theora (converting to ogv/theora video) writing ...
0
votes
2answers
1k views

How can I curl the output of another command

I want to pass curl the output from awk ./jspider.sh http://www.mypage.com | grep 'resource' | awk '{print $4}' | curl OUTPUT_FROM_AWK | grep myString How can I achieve this?!
0
votes
1answer
695 views

“find | grep | awk” fails miserabily

I'm scanning for all shell scripts on my server, and are doing this by the following command: find / -type f -exec file --mime-type {} \; | grep "text/x-shellscript" This is working fine, and here ...
5
votes
3answers
3k views

How can I specify command line arguments using pipes in Linux?

I'm a newbie to shell programming and have no idea how to solve this problem. I just downloaded a file from the Internet to the default directory ~/Downloads. I want to move that file to another ...
3
votes
3answers
2k views

How can I grep in source files for some text?

At the moment I'm using two commands, I'm sure there must be a better way... wim@wim-acer:~/ffmpeg$ find . -name "*.h" -print0 | xargs -0 grep -i invalid\ preset wim@wim-acer:~/ffmpeg$ find . -name ...
10
votes
4answers
15k views

How can I pipe output of ffmpeg to ffplay?

How can I pipe the output of ffmpeg to ffplay? At the moment I use a workaround in bash : mkfifo spam (ffplay spam 2> /dev/null &) ; capture /dev/stdout | ffmpeg -i - spam
9
votes
3answers
8k views

Passing two arguments to a command using pipes

Usually, we only need to pass one argument: echo abc | cat echo abc | cat some_file - echo abc | cat - some_file Is there a way to pass two arguments? Something like {echo abc , echo xyz} | cat ...
3
votes
2answers
696 views

Pipes, shell scripts and ulimit

I have a command that I'm calling from code: execvp('generate', ...) which is an executable program that my code communicates with via stdin, stdout and stderr. This works fine, not a single ...
25
votes
4answers
4k views

How can I save the current contents of less to a file?

If I've piped the results of a command to less and then decided that I want to save the contents to a file, is this possible? I've tried setting a mark a at the end of the buffer, and then returning ...
2
votes
1answer
230 views

Is there any way to pipe local output to an SSH server as well?

Is there any way to set up a local process, but have the output also go to a terminal that has SSH'd into my machine?
3
votes
1answer
632 views

Linux: redirecting stdout and stderr

I want to write stdout to a file but also prints stdout and stderr. I tried using tee: prog | tee stdout.txt but this causes the printed stderr and stdout to be interleaved incorrectly, i.e. if the ...
2
votes
1answer
3k views

BASH - Check if unnamed pipe is empty

My problem is, I want a script which reads content from a pipe, checks if it's empty and output it if not, as seen here: #!/bin/bash var=$(cat -) if [ -n "$var" ] then echo "$var" else echo ...
6
votes
2answers
2k views

How do you determine the actual command that is piping into you?

Let's say I have a bash script called log.sh. In this script, I want to read in input from a pipe, but I also want to know the command used to pipe input into me. Example: tail -f ...