pass more than one input with pipe ("|")


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pass more than one input with pipe ("|")
# 1  
Old 03-22-2010
pass more than one input with pipe ("|")

Hi everyone,

Is there any way to use the pipe "|" operator to pass more than one input? For instance do:
(command1) (command2) | command3
with command 3 taking 2 parameters?

or maybe using ``s?

Thanks!

Anthony
# 2  
Old 03-22-2010
here is the sample I used before,

Code:
diff <(ls /dir1) <(ls /dir2)

so you can try:

Code:
command3 <(command1) <(command2)

# 3  
Old 03-22-2010
or literally:
Code:
( command1; command2 ) | command3

e.g.:
Code:
$ (ls ; ls -la ) | egrep "abrow|firef"
abrowser
abrowser-3.5
firefox
firefox-3.5
firefox-3.5-restart-required.update-notifier
firefox.sh
lrwxrwxrwx   1 root root      7 2010-02-18 22:05 abrowser -> firefox
lrwxrwxrwx   1 root root      7 2010-02-18 22:05 abrowser-3.5 -> firefox
lrwxrwxrwx   1 root root     28 2010-02-18 22:05 extensions -> ../firefox-addons/extensions
-rwxr-xr-x   1 root root  75584 2010-02-15 00:17 firefox
lrwxrwxrwx   1 root root      7 2010-02-18 22:05 firefox-3.5 -> firefox
-rw-r--r--   1 root root    460 2010-02-15 00:12 firefox-3.5-restart-required.update-notifier
-rwxr-xr-x   1 root root   4277 2010-02-15 00:13 firefox.sh
lrwxrwxrwx   1 root root     25 2010-02-18 22:05 plugins -> ../firefox-addons/plugins
$

# 4  
Old 03-22-2010
Another way is with named pipes or with tee.

Example:

Code:
$ touch foo{1..5}
$ touch bar{15..19}

ls | tee >(grep '^foo' | sort >foo.txt)  \
           >(grep '^bar' | sort >bar.txt) \
               | egrep '^foo|^bar'

bar.txt
bar15
bar16
bar17
bar18
bar19
foo.txt
foo1
foo2
foo3
foo4
foo5
$ cat foo.txt
foo.txt
foo1
foo2
foo3
foo4
foo5
$ cat bar.txt
bar.txt
bar15
bar16
bar17
bar18
bar19

The command substitution in bash of the type

Code:
diff <(ls dir1) <(ls dir2)

is a form of named pipe; bash just cleans up after it by deleting the file it creates. You can use named pipes as in this example:

Code:
$ # create a named pipe called d1:
$ mkfifo d1
$ # send something to it in the background:
$ ls -l > d1 &
[2] 6332
$ # create a file that is new:
$ touch new3 
$ ls -l > lsfile
$ #compare a pipe and a file:
$ diff <(cat < d1) lsfile
< total 33224
---
> total 33208
30c30
< prw-r--r--   1 andrew  andrew         0 Mar 22 17:14 d1
---
> prw-r--r--   1 andrew  andrew         0 Mar 22 17:12 d1
57c57
< -rw-r--r--   1 andrew  andrew      5903 Mar 22 17:14 lsfile
---
> -rw-r--r--   1 andrew  andrew         0 Mar 22 17:14 lsfile
[2]+  Done                    ls -l > d1

Notice that "new" does not show up as a difference. The ls -l in the background is only executed when the pipe is read. Note also that the file "d1" will need to be deleted when you are done.

Using tee, mkfifo for named pipes, and command substitution, you can do what you describe.
# 5  
Old 03-23-2010
That did the trick Smilie

Thanks so much for the help and explanations guys, that is GREATLY appreciated! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

How to allign output data in UNIX that is separated with a pipe "|" symbol ?

Experts , In the given output of the log file, the 2nd field that is separated by "|" pipe is not aligned well due to the uneven data length, I would like it to align the 2nd column with 37 length (that is disturbed in the output) including the pipe . The two pepe "|" would be in a aligned way... (2 Replies)
Discussion started by: rveri
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

input string="3MMTQSZ348GGMZRQWMJM4SD6M";output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6

input string="3MMTQSZ348GGMZRQWMJM4SD6M" output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6M" using linux shell script (4 Replies)
Discussion started by: pankajd
4 Replies

7. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

8. Shell Programming and Scripting

check input = "empty" and "numeric"

Hi how to check input is "empty" and "numeric" in ksh? e.g: ./myscript.ksh k output show: invalid number input ./myscript.ksh output show: no input ./myscript.ksh 10 output show: input is numeric (6 Replies)
Discussion started by: geoffry
6 Replies

9. UNIX for Advanced & Expert Users

pf not working properly even with only "pass in all" and "pass out all" rules

i have two rules in my pf.conf file, "pass in all" and "pass out all" i was having issues with getting pf working to begin with, so i went with starting from nothing and working on up. i have an ultrasparc ultra1 200e, with an added 4-port fast ethernet sbus card, running "3.4 GENERIC#85... (4 Replies)
Discussion started by: xyyz
4 Replies
Login or Register to Ask a Question