0

I am running two scripts on two terminals in iTerm on Mac. On one terminal a series of tests are being run and the second terminal continuously prints the temperature at repeated intervals. There is no synchronization between the two scripts.

  Terminal1     Terminal2
    Test1         50C
                  51C
                  52C
    Test2         49C
                  53C

What I want to do is to capture these two outputs side by side and save it to a file.

The output can look like this:

    Test1         50C
    Test1         51C
    Test1         52C
    Test2         49C
    Test2         53C

It need not be the exact same format as above but at least it should be clear that when a Test was running, what the temperature samples were at that time. The output need not be a live output. It's okay if it is collated later.

Divine Cosmos
  • 327
  • 1
  • 2
  • 8

1 Answers1

0

Try this:

#!/bin/bash

first=$1
second=$2

actual=""
while IFS= read -r lineA && IFS= read -r lineB <&3; do
    if [[ -z "${lineA// }" ]]; then
        echo "$actual   $lineB"
    else
        echo "$lineA    $lineB"
        actual=$lineA
    fi
done <$first 3<$second

Where $1 and $2 are the two files passed by arguments.

Usage:

./join.sh first.txt second.txt

Regards.