Bash: Split stdout from multiple parallel commands into columns

I run several commands in a bash script using single ampersands, for example:

commandA & commandB & commandC

Each of them has its own conclusion stdout, but they all mix together and flood the console in an incoherent mess.

I am wondering if there is an easy way to pass my results into my own columns ... using a command columnor something like that. i.e. sort of:

commandA | column -1 & commandB | column -2 & commandC | column -3

New to this kind of thing, but from the initial digging seems like something like pr might be a ticket? or team ...? column

+4
source share
3 answers

, .

, . : multiview. , ?

stdout/stderr , "", :

fooProcess | multiview -s & \
barProcess | multiview -s & \
bazProcess | multiview -s & \
multiview

. , -s:

fooProcess | multiview -s "foo" & \
barProcess | multiview -s "bar" & \
bazProcess | multiview -s "baz" & \
multiview

, .

, !

+2

pr - , . , ( <(command)):

pr -m -t <(while true; do echo 12; sleep 1; done) \
         <(while true; do echo 34; sleep 2; done)

:

12                                  34
12                                  34
12                                  34
12                                  34

, - , . , , .

, tmux screen , . , , B A commandC . , , , .

, , :

this is something that commandA outputs and is
    and here is something that commandB outputs
interleaved with the other output, but visually
you might have an easier time distinguishing one
        here is something that commandC outputs
    which is also interleaved with the others
from the other
+3

Script print three vertical lines and a timer for each line containing output from a single script. Comment on everything you don’t understand and add answers to my answer as needed

Hope this helps :)

#!/bin/bash
#Script by jidder

count=0
Elapsed=0
control_c()
{
    tput rmcup
    rm tail.tmp
    rm tail2.tmp
    rm tail3.tmp
    stty sane
}


Draw()
{
       tput clear
       echo "SCRIPT 1                                                                                                                     Elapsed time =$Elapsed seconds"
        echo "------------------------------------------------------------------------------------------------------------------------------------------------------"
        tail -n10 tail.tmp
        tput cup 25 0

        echo "Script 2                                                                                                                                                   "
        echo "------------------------------------------------------------------------------------------------------------------------------------------------------"
        tail -n10 tail2.tmp
        tput cup 50 0

        echo "Script 3                                                                                                                                                   "
        echo "------------------------------------------------------------------------------------------------------------------------------------------------------"
        tail -n10 tail3.tmp
}


Timer()
{
        if [[ $count -eq 10  ]]; then
                Draw
                ((Elapsed = Elapsed + 1))
                count=0
        fi


}
main()
{
    stty -icanon time 0 min 0
    tput smcup
    Draw
    count=0
    keypress=''
    MYSCRIPT1.sh > tail.tmp &
    MYSCRIPT2.sh > tail2.tmp &
    MYSCRIPT3.sh > tail3.tmp &

    while [ "$keypress" != "q" ]; do
            sleep 0.1
            read keypress
            (( count = count + 2 ))
            Timer
    done

    stty sane
    tput rmcup
    rm tail.tmp
    rm tail2.tmp
    rm tail3.tmp
    echo "Thanks for using this script."
    exit 0
}

main

trap control_c SIGINT
+1
source

Source: https://habr.com/ru/post/1544245/


All Articles