Need help with awk

#!/bin/bash

ARCHIVE="$PWD"
#ARCHIVE="/home/kschmidt/public_html/Files/DrMathArchive"

echo `ls "$ARCHIVE"`
ls "$ARCHIVE" | while read DIR
do
#     echo $DIR

#        [ -d "$DIR" ] || continue # Ignore non-directories
#echo "Dir is: "$ARCHIVE"/$DIR"

       for EACHFILE in "$ARCHIVE/$DIR/prob"*
       do
#           echo $EACHFILE
              TEMP3="${EACHFILE##*/}"

              TEMP2="${TEMP3%%_*}"

              # Use globbing to count files.
              set -- "$ARCHIVE/$DIR/${TEMP2}"*
              echo "$TEMP2" "$#"
        done
done > outputfile

sort -u outputfile -o outputfile
sort -k2 -nr outputfile -o outputfile
GREATER=head -1  outputfile | awk '{print $2}'
echo "This is : $(GREATER)"

awk '{if ($2 = 10 ) {print $1}}' outputfile

At the end of my code I am trying to store head -1 outputfile | awk '{print $2}' into GREATER, but everything I do fails. I need to do this because I need that value to compare in the last if so instead of 10 I need ${GREATER}. Any ideas?

Try

 
GREATER=`head -1  outputfile | awk '{print $2}'`

I have tried that, but it does not work, no idea why?

Can you elaborate the issue that you observe?

yes it states greater no command found

Your problem is this line:

echo "This is : $(GREATER)"

should be

echo "this is $GREATER"

It's trying to execute GREATER.

You also don't need to use head if you are using awk:

GREATER=$(awk '{print $2; exit(0); }' outputfile )
1 Like

Thank you That helped alot