0

I am tailing two files at the same time, side by side, I can't get a version to work that doesn't use temporary files F1.tmp and F2.tmp. I would like to use watch to call this script.

Pretty sure I am missing something about command expansion and piping outputs.

FNAME1="$(ls -t | grep '.out'|  head -n2 | sort | head -n1)"
FNAME2="$(ls -t | grep '.out'|  head -n2 | sort | tail -n1)"
KEY="TIME STEP ="
TS1=`grep "$KEY" "$FNAME1" | tail -n 3`
TF1=`tail -n40  "$FNAME1"`
F1="$FNAME1""$TS1""$TF1\n"

TS2=`grep "$KEY" "$FNAME2" | tail -n 3`
TF2=`tail -n40  "$FNAME2"`
F2="$FNAME2\n\n$TS2\n\n$TF2\n"
echo "$FNAME1" > F1.tmp
echo "$TS1" >> F1.tmp
echo "$TF1" >> F1.tmp
echo "$FNAME2" > F2.tmp
echo "$TS2" >> F2.tmp
echo "$TF2" >> F2.tmp
pr -m -W 144 F1.tmp F2.tmp




pr -m -W 144 <(echo "$TS1") <(echo "$TS2") 

Doesn't work

pr -m -W 144 <($TS1) <($TS2)

Doesn't either. For context this is used to monitor CFD output files running on an HPC cluster.

below works on its own, but not when called using watch:

FNAME1="$(ls -t | grep '.out'|  head -n2 | sort | head -n1)"
FNAME2="$(ls -t | grep '.out'|  head -n2 | sort | tail -n1)"
KEY="TIME STEP ="
TS1=`grep "$KEY" "$FNAME1" | tail -n 3`
TF1=`tail -n40  "$FNAME1"`
F1="$FNAME1\n\n$TS1\n\n$TF1\n"

TS2=`grep "$KEY" "$FNAME2" | tail -n 3`
TF2=`tail -n40  "$FNAME2"`
F2="$FNAME2\n\n$TS2\n\n$TF2\n"
pr -m -W 144 <(printf "$F1") <(printf "$F2")

Seams to work ok on putty, juice ssh makes a mess of the formatting of you change the font size.

Note: I'm searching for occurrences of '$KEY' in the file '$FNAME1'.

  • Do you intend on tailing the files continuously or just fetching certain lines ? If just a few lines, it seems like it could be made a lot simpler. – Sergiy Kolodyazhnyy Mar 15 at 20:44
  • Currently I'm using watch to run this script continuously. I think I've fixed it, partly due to juice ssh messing about with the formatting. – L Selter Mar 15 at 20:47
  • TS1 declaration seems wrong. If you intended on filtering contents of FNAME variable, then it should be grep "$KEY" <<< "$FNAME1" if your shell is bash, or just pipe if that's /bin/sh shell – Sergiy Kolodyazhnyy Mar 15 at 20:48
  • @sergiy I'm searching for occurrences of '$KEY' in the file '$FNAME1' – L Selter Mar 15 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.