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

removed ` in if condition, solved

Thread Tools Search this Thread Display Modes
Old Unix and Linux 07-13-2017   -   Original Discussion by kieranfoley
kieranfoley's Unix or Linux Image
kieranfoley kieranfoley is offline
Registered User
Join Date: May 2009
Last Activity: 11 December 2017, 8:50 AM EST
Posts: 47
Thanks: 11
Thanked 1 Time in 1 Post
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

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

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


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

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

Note that


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

This is my if statement

    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
        echo -e "$GROUP did not start at $TIME - Please check\n" >> $OUTDIR/nonrunners.out

---------- 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

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 06:44 AM
error in if statement Swapna173 UNIX for Dummies Questions & Answers 1 03-18-2009 09:00 AM
Error in IF statement ravi214u Shell Programming and Scripting 4 07-14-2008 11:44 AM
error in if statement capri_drm Linux 16 05-14-2008 03:00 PM
Error with if statement..Please help jisha Shell Programming and Scripting 1 01-16-2008 07:13 AM

All times are GMT -4. The time now is 09:58 AM.