Solved

paste two outputs

Posted on 2002-06-22
9
228 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
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 51

Expert Comment

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

828 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