Search and match the value

Hi ,

I have to match the table column via shell script ,where col name is value,like if table's column value is N then proceed to next main script.if not then exit with Some message.'not validated'

Table o/p comes like this way.where value is column name.

VALUE
-------
 N
(1 row)

I'm sure this is doable in bash alone, but I'm feeling dumb. So, here's a effort that also uses awk

output=`awk 'NR == 1 {for (i = 1 ; i <= NF ; i++) {if ($i == "VALUE") {colnum = i ; next}}} NR == 3 && colnum == "N" {stat = "V"} NR == 3 && colnum != "N" {stat = "NV"} END {print stat}' inputfile`

if [ "$output" == "NV" ]
then
   echo "Not validated"
   exit 1
fi

<rest of script>

I'm making all sorts of assumptions there, but maybe that's a starting point.

You can use an awk one liner for this. If the table data comes from a file:

awk 'NR==3{gsub(/[[:space:]]/,"");RC=($0=="43")?0:1};END{if (RC>0) print "Not validated.";exit RC}' tablefile

Thanks!

I tried this ,but looks like I'm missing something.For all run I 'm getting NO.Please help

Aim: check the value in file value.out (above stated).if value is N then go and start main script (here i kept echo yes).if not N i.e Y then start another script.(here i kept echo no ) for test.

#!/bin/bash
x=`sed -n '3p' value.out`
        S1='N'
        S2='Y'
        if [ "$x" == "$S1" ];
        then
echo yes
else echo No              
fi

Try

{ read A; read A; read A; } <value.out; [ "$A" = "N" ] && echo yes || echo no

Yes. The "problem" is that the (correct) result of the sed command is actually N , notice the preceding whitespace. So right now you are comparing " N" and "N" and thus the result is No.

Solution: Remove that leading whitespace and try again. There are many ways to perform that, I prefer this:

x=`sed -n '3p' value.out | sed 's/^ //'`