Help Regarding AWk and IF THEN ELSE Statement

Hi,

I have a data file which contains record count.

So doing [wc -l rightfit_balancing_count.dat | awk '{print $1}'] gives me the record count stored in the file.

Now, i want to send a mail from UNIX, if the record count is equal to 0,otherwise it should do nothing.

Any help please???

Hi Shell_learner,

To test the code use:

sendmail=10
if [ $sendmail -eq 10 ]
then
  echo "The word count is $sendmail"
fi

After that adapt to your needs doing something like this:

sendmail=$(wc -l rightfit_balancing_count.dat | awk '{print $1}')
if [ $sendmail -eq 0 ]
then
  echo "This is the word count" | mail -s "Current word count" counting_words@shell_learner.com
fi

Hope it helps.

Regards

wc -l rightfit_balancing_count.dat will give you the number of records ( truly, newlines) in the file "rightfit_balancing_count.dat" and not the content of the line.