Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Awk/if statement error

Shell Programming and Scripting


Tags
removed ` in if condition, solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago
kieranfoley kieranfoley is offline
Registered User
 
Join Date: May 2009
Last Activity: 13 July 2017, 7:05 AM EDT
Posts: 37
Thanks: 10
Thanked 0 Times in 0 Posts
Awk/if statement error

Can anybody tell the correct way to use the following awk pattern check within an if statement?

When I run this command outside of the if statement


Code:
cat /tmp/test2.out | awk -v T=$TIME -v G=$GROUP -v C=$CDATE '$0 ~ T && $0 ~ G && $0 ~ C' | grep -i "Starting the group"

I get the following result which is correct


Code:
71193 07/13/2017 05:30:00 AM  0 0 0 2291124000 26204 0 seinwsprd01 nsrd NSR info Savegroup Info: Skipped starting the group 'Misc_FS_Monthly_530'.


The 3 variables are defined as


Code:
TIME=05:30
GROUP=Misc_FS_Yearly_530
CDATE=07/13/2017


But when I execute the command withing an if statement in a bash shell I get the following error.


Code:
./backup_checker.sh: line 56: 71193: command not found

Note that
Code:
71193

is the first entry in the line that matches the pattern.

This is my if statement


Code:
    if `cat /tmp/test2.out | awk -v T=$TIME -v G=$GROUP -v C=$CDATE '$0 ~ T && $0 ~ G && $0 ~ C' | grep -i "Starting the group"` > /dev/null
      then
         :
      else
        echo -e "$GROUP did not start at $TIME - Please check\n" >> $OUTDIR/nonrunners.out
    fi

---------- Post updated at 12:02 PM ---------- Previous update was at 11:39 AM ----------

I figured out the issue. I do not need to use ` in the if statement/condition.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error in if statement nareshkumar522 Shell Programming and Scripting 16 10-18-2010 05:44 AM
error in if statement Swapna173 UNIX for Dummies Questions & Answers 1 03-18-2009 08:00 AM
Error in IF statement ravi214u Shell Programming and Scripting 4 07-14-2008 10:44 AM
error in if statement capri_drm Linux 16 05-14-2008 02:00 PM
Error with if statement..Please help jisha Shell Programming and Scripting 1 01-16-2008 06:13 AM



All times are GMT -4. The time now is 02:45 AM.