Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

paste two outputs

Posted on 2002-06-22
9
Medium Priority
?
233 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

688 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