check for null

hi,

i have 3 lines of output , if second line exists then only condition within the if loop has to exeute other wise it has exit from loop.
i had tried like this but not getting

please help me ...

Code:

if [ condition]; then 
 
    echo "success"
else
 echo ""

Is there a string/pattern you expect in the 2nd line or is it just a check on how many lines you have overall?

hi,

i have input like this,
i have to check that second line exists or not ? :confused:
which condition i have use??? please help me

INPUT:

Machine ID     Machine Name   Master    Check Error Files   MachineComments
-----------------------------------------------------------------------
1                     SSZ0797             Y              Y                      ssz0797
2                                      SSZ0795             N              Y                      SLAVE_1
3                                      SSZ0796             N              Y                      SLAVE_2

when you tell you are checking for the second line, is it that you are checking for the existance of

2 SSZ0795 N Y SLAVE_1

, or any specific row..??? Machine ID, Machine Name etc....

please be a little detailed...

i am checking for second line existence,

if second line exists some code has to execute otherwise it has to exit from the loop

# cat check
1 SSZ0797 Y Y ssz0797
2 SSZ0795 N Y SLAVE_1
3 SSZ0796 N Y SLAVE_2
if [[ `grep -w "2 [[:alnum:]][[:alnum:]]*" check` ]] ; then echo "2 line is exist"; else echo "2 line is not exist"; fi
2 line is exist
# cat check
1 SSZ0797 Y Y ssz0797
2
3 SSZ0796 N Y SLAVE_2
# if [[ `grep -w "2 [[:alnum:]][[:alnum:]]*" check` ]] ; then echo "2 line is exist"; else echo "2 line is not exist"; fi
2 line is not exist

its not working :frowning:
i am taking the input from one file and trying to check the second line existence

SWADM=$SWDIR/util/swadm

SERVEREXISTS=`$SWADM show_servers | awk '{print $1}'| head -5 | tail -1`

if [ "$SERVEREXISTS" != "" ]; then 
echo "line exists"

else
echo "line does not exits"
fi

please help me...

 
SERVEREXISTS=`$SWADM show_servers | awk '{print $1}'| head -5 | tail -1`

how is the output ?

number will be the output..

---------- Post updated at 04:45 AM ---------- Previous update was at 04:43 AM ----------

i have tried the first value in the second line is null or not?

actually i want to check for the exitence of second line...:confused: