Can we use 'paste' command not only for two files, but for two standard outputs, too?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Can we use 'paste' command not only for two files, but for two standard outputs, too?

Jin Choi
This post was updated on .
Hello :)
Thanks for your great materials. I learn a lot!

By the way, I got stuck while I was trying to use the tool, 'paste'
Okay, what I'm trying to do here is to get the mbr in hex-code format and ascii-code format, pasted together!
I can do this using temporary files with commands as below:
# dd if=/dev/sda bs=512 count=1 | od -t x1 -w5> /tmp/tmp1.txt
# dd if=/dev/sda bs=512 count=1 | od -c -w5 > /tmp/tmp2.txt
# paste /tmp/tmp1.txt /tmp/tmp2.txt

The result will look like this:
0000000 eb 58 90 4d 53   0000000 353   X 220   M   S
0000005 57 49 4e 34 2e   0000005   W   I   N   4   .
0000012 31 00 02 08 20   0000012   1  \0 002  \b    
0000017 00 02 00 00 00   0000017  \0 002  \0  \0  \0
0000024 00 f8 00 00 3f   0000024  \0 370  \0  \0   ?
0000031 00 ff 00 00 00   0000031  \0 377  \0  \0  \0
0000036 00 00 00 a0 f0   0000036  \0  \0  \0 240 360
0000043 00 19 3c 00 00   0000043  \0 031   <  \0  \0
0000050 00 00 00 00 02   0000050  \0  \0  \0  \0 002
0000055 00 00 00 01 00   0000055  \0  \0  \0 001  \0
0000062 06 00 00 00 00   0000062 006  \0  \0  \0  \0
0000067 00 00 00 00 00   0000067  \0  \0  \0  \0  \0
0000074 00 00 00 00 80   0000074  \0  \0  \0  \0 200
0000101 00 29 a2 82 84   0000101  \0   ) 242 202 204
0000106 d7 4e 4f 20 4e   0000106 327   N   O       N
0000113 41 4d 45 20 20   0000113   A   M   E        
0000120 20 20 46 41 54   0000120           F   A   T
0000125 33 32 20 20 20   0000125   3   2            
0000132 0e 1f be 74 7e   0000132 016 037 276   t   ~
0000137 ac 22 c0 74 06   0000137 254   " 300   t 006
0000144 b4 0e cd 10 eb   0000144 264 016 315 020 353
0000151 f5 b4 00 cd 16   0000151 365 264  \0 315 026
0000156 b4 00 cd 19 eb   0000156 264  \0 315 031 353
0000163 fe 54 68 69 73   0000163 376   T   h   i   s
0000170 20 70 61 72 74   0000170       p   a   r   t
0000175 69 74 69 6f 6e   0000175   i   t   i   o   n
0000202 20 64 6f 65 73   0000202       d   o   e   s
0000207 20 6e 6f 74 20   0000207       n   o   t    
0000214 68 61 76 65 20   0000214   h   a   v   e    
0000221 61 6e 20 6f 70   0000221   a   n       o   p
0000226 65 72 61 74 69   0000226   e   r   a   t   i
0000233 6e 67 20 73 79   0000233   n   g       s   y
0000240 73 74 65 6d 20   0000240   s   t   e   m    
0000245 6c 6f 61 64 65   0000245   l   o   a   d   e
0000252 72 20 69 6e 73   0000252   r       i   n   s
0000257 74 61 6c 6c 65   0000257   t   a   l   l   e
0000264 64 20 6f 6e 20   0000264   d       o   n    
0000271 69 74 2e 0a 0d   0000271   i   t   .  \n  \r
0000276 50 72 65 73 73   0000276   P   r   e   s   s
0000303 20 61 20 6b 65   0000303       a       k   e
0000310 79 20 74 6f 20   0000310   y       t   o    
0000315 72 65 62 6f 6f   0000315   r   e   b   o   o
0000322 74 2e 2e 2e 00   0000322   t   .   .   .  \0
0000327 00 00 00 00 00   0000327  \0  \0  \0  \0  \0
*   *
0000670 ed b4 04 00 00   0000670 355 264 004  \0  \0
0000675 00 00 00 02 00   0000675  \0  \0  \0 002  \0
0000702 0c 1a 19 55 01   0000702  \f 032 031   U 001
0000707 00 00 00 93 dc   0000707  \0  \0  \0 223 334
0000714 14 00 00 28 14   0000714 024  \0  \0   ( 024
0000721 55 0c 9c c7 d5   0000721   U  \f 234 307 325
0000726 00 e0 14 00 00   0000726  \0 340 024  \0  \0
0000733 c0 db 00 00 00   0000733 300 333  \0  \0  \0
0000740 00 00 00 00 00   0000740  \0  \0  \0  \0  \0
*   *
0000776 55 aa   0000776   U 252

But I'd love to get the same result without any file saves, in only command, by all means, whether with pipelining or xargs or not, for example,
# paste `dd if=/dev/sdd bs=512 count=1 | od -t x1 -w5` `dd if=/dev/sdd bs=512 count=1 | od -c -w5`
Only if it works....but it doesn't, I tried.

So, what do you think, guru? Is it just that I don't know what to do, or is it unfeasible?
Reply | Threaded
Open this post in threaded view
|

Re: Can we use paste command for two standard outputs by all means?

Guru
Administrator
To use the paste command for the output of other commands, use it like this:

$ paste <(command1) <(command2)

An example:
$ paste <(cat f1) <(cat f2)


Your case should be something like this(not tested):

$ paste <(dd if=/dev/sda bs=512 count=1 | od -t x1 -w5) <(dd if=/dev/sda bs=512 count=1 | od -c -w5)


Reply | Threaded
Open this post in threaded view
|

Re: Can we use paste command for two standard outputs by all means?

Jin Choi
oh! It works like a charm!
Thank you so much.
Follow-up question!
1. I check man page and info page for this technique you taught me, but it seems not to be explained there. So, does this technique have a specific name, or is it just a special forms of redirection for this kind of situation?

2. Is this technique only applied to 'paste' command or is it universal(?) like redirection or pipelining?

Thank you so much ~
Reply | Threaded
Open this post in threaded view
|

Re: Can we use paste command for two standard outputs by all means?

Guru
Administrator
1. I check man page and info page for this technique you taught me, but it seems not to be explained there. So, does this technique have a specific name, or is it just a special forms of redirection for this kind of situation? 
[The Unix School]: I am not sure of a name for this technique, but this is used in typical cases like this where I want to avaid re-directing to a file and then using it.

2. Is this technique only applied to 'paste' command or is it universal(?) like redirection or pipelining? 
[The Unix School]: Not only for paste command, its a general thing.