I am trying to create a bash script to search for lines that contain a certain keyword in .log files and sort them at the end. I am trying to save all the lines in an unsorted temporary document and sort them at the end by the following script but it keeps giving me the error of ambiguous redirect. I was wondering if anyone could give me any hint.
#! /bin/bash
MYTMPDIR='(mktemp -d)'
for i in `ls *.log`
do
grep Energy $i | cut -d' ' -f8| tail -1 >$MYTMPDIR/energy
paste energy nr >>$MYTMPDIR/sort_energies
done
cat $MYTMPDIR/sort_energies| sort -n >sorted_energies
trap 'rm -rf -- "$MYTMPDIR"' EXIT