Solved

paste two outputs

Posted on 2002-06-22
9
230 Views
Last Modified: 2010-04-21
In order to paste two outputs from two commands, I have
to re-direct the outputs to 2 temporary files and then paste
them together, such as,
  cmd1 > tmpfile1
  cmd2 > tmpfile2
  paste tmpfile1 tmpfile2 > the_wanted_results

Can some one think of way to elimilate the use of
the temporay files, i.e., make it one liner instead
of using three lines.
0
Comment
Question by:geermu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 7101138
That's easy, do it like so:

cmd1 >wanted_results
cmd2 >>wanted_results

On the first command the single redirection operator (>) created a new file to hold what cmd1 produced on STDOUT. The second line used the append redirection operator that appends data to an existing file (and on most Unixen it will create the file if it doesn't exist_. So in general it is safe to do:

cmd1 >>wanted_results
cmd2 >>wanted_results
cmd3 >>wanted_results
0
 

Expert Comment

by:hotbox
ID: 7101222
yes,use >> to append your others output to same file.
0
 

Author Comment

by:geermu
ID: 7101294
No, it is not append.
It is paste.
I have increased the points. I guess it may need to
combine sub-shell and pipe to do it.
Thanks.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 51

Expert Comment

by:ahoffmann
ID: 7102095
(cmd1; cmd2)>the_wanted_results
0
 
LVL 21

Expert Comment

by:tfewster
ID: 7103606
I doubt you can do this from the command line, as:
a) cmd1 will put a carriage return at the end of each output line, so the output from cmd2 will appear on the next line instead of tab-separated;
b) cmd1 & cmd2 are not synchronised, so cmd1 may write 2 lines of output before cmd2 writes its first output.

Of course, it depends on the commands. If you tell us more about what you are trying to do, we may be able to suggest an alternative.

0
 
LVL 5

Accepted Solution

by:
ecw earned 150 total points
ID: 7112358
in ksh...
cmd1 |& exec 4>&p 3<&p cmd2 |& while read line1 <&3 && read line2 <&p ; do echo "$line1 $line2" ; done ; cat <&3 ; cat <&p ; exec 4>&- 4<&-

all one line, seriously though what you're tryng to do can't be done unless your OS has /dev/fd support and your shell does not gratuitously close fd's when exec'ing a command.  IIRC, bourne shell leaves all fd's open, ksh and its kin close all but std{in,out,err}.
0
 
LVL 84

Expert Comment

by:ozo
ID: 7112474
Would you settle for two lines and 1 temporary file?
0
 
LVL 9

Expert Comment

by:PeterMac
ID: 7126970
Sorry missed this earlier,

paste 'cmd1' 'cmd2' > result_file

quotes around cmd1 & cmd2 are backquote, execute in situ, and replace with standard out from comand.
0
 
LVL 5

Expert Comment

by:ecw
ID: 7127207
 paste [-s] [-d list] file...
Hmm. I don't think "paste 'cmd1' 'cmd2' > result_file" will do.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question