LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   paste output of two commands (https://www.linuxquestions.org/questions/linux-newbie-8/paste-output-of-two-commands-4175436436/)

forumbaba 11-09-2012 12:12 PM

paste output of two commands
 
I am trying the following command but its not working:

paste < (awk '{ print $1 }' file1 | program1 ) < (awk '{ print $2 }' file2 | program2)

markush 11-09-2012 05:29 PM

Could you please explain, what you expected what the command would do. What are program1 and program2?

Markus

forumbaba 11-09-2012 10:17 PM

Quote:

Originally Posted by markush (Post 4826157)
Could you please explain, what you expected what the command would do. What are program1 and program2?

Markus

Hi,

I want to print the output of two independent commands on the same line side by side, for example:

If output of command one is "AAAA" and output of command two is "BBBB" then I want to produce an output such as:

AAAA BBBB

program1 and program2 are scripts that take input, perform some calculations and produce output.


Thanks

PS: when I use my earlier line I get the error: Missing name for redirect.

rknichols 11-09-2012 10:29 PM

I can't replicate that same error message, but you need to lose the spaces between "<" and "(". The "<(" that introduces process substitution is a single token and must not be broken up.

David the H. 11-10-2012 01:47 PM

I don't see that this question is any different from the topic you have running already here:

http://www.linuxquestions.org/questi...6/#post4825971


We usually want to keep conversations on the same topic together. So only create a new threads if your question is substantially different from the previous ones.


But yeah, to follow up on the above, bash's process substitution is a simplified, automated way to create a background fifo. In essence "<(..)" (no space) acts like a file that contains the output of the commands contained in it.

If needed, this can be then redirected as normal with another "<". e.g.:

Code:

$ tr ":" "-" < <( echo "foo:bar" )
foo-bar

Note that the space between the two "<" characters is necessary.

But for commands that can read from files directly, the extra redirection isn't needed:

Code:

$ cat <( echo "foo:bar" | tr ":" "-" )
foo-bar



All times are GMT -5. The time now is 12:48 PM.