Solved

paste two outputs

Posted on 2002-06-22
9
226 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
Comment Utility
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
Comment Utility
yes,use >> to append your others output to same file.
0
 

Author Comment

by:geermu
Comment Utility
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
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
(cmd1; cmd2)>the_wanted_results
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 20

Expert Comment

by:tfewster
Comment Utility
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
Comment Utility
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
Comment Utility
Would you settle for two lines and 1 temporary file?
0
 
LVL 9

Expert Comment

by:PeterMac
Comment Utility
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
Comment Utility
 paste [-s] [-d list] file...
Hmm. I don't think "paste 'cmd1' 'cmd2' > result_file" will do.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Not able to see disks at the OS level 10 15
removing nim resources 5 37
UNIX network port 5 45
Python Assistance 7 30
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now