how to grep and then to compare

Hello to all,
i am new to scripting. I had to ques...1) If I had a variable $a which contains value i.e abc= jack
I want to grep it first and then put into the variable lets say $b.
Ques 2) If there is a file name.txt in which there are 15-20 names
-----name.txt------
jack|male|london
prink|male|hague
john|male|france
nincey|female|calif
-------------------
now I want to compare the value of $b with each name in name.txt
Thank you....

Hi Ravi,

 
 awk -v search_strng=$ma  -F"|" '{for(i=1;i<=NF;i++){if($i==search_strng) print search_strng;print"found" } }' input_file

will search for the value in the file .But wht ur trying to acheive ?.. still i am not understnd..

regards
Sastry

I want to read from the unix file....which would act as a database... so it will authenticate the username and password of user....so will it work or not...I would check it....So you returned a string "found"....please tell me how to call the next page after login authentication....
Please tell me what NF stands for and How I can grep the string after "=" sign.....
i.e. name= rohit
Thanks...
Regards,
Ravi

 
I want to read from the unix file....which would act as a database... so it will authenticate the username and password of user....so will it work or not...I would check it....So you returned a string "found"....please tell me how to call the next page after login authentication....

really i did n't understand
might be u r trying something like php or html it seems.

 
Please tell me what NF stands for and How I can grep the string after "=" sign.....

NF stands for No.of fields in a line used by awk

if u want to check for "rohit"

 
cat inp_file.txt 
 
name=rohit 
 
awk -F"=" '{ if ( $2==search_string) print "found" }'  inp_file.txt

yes you are right... I have a login page..through which I am sending form data by get method. In get method, data go by name=rohit and stored in default variable $QUERY_STRING. Now $QUERY_STRING is name=rohit.
now I want to grep rohit from itand then in the script I would check whether this user rohit exist or not by compairing it with the unix file. If the username exist then I would check the corresponding password.
If all the authentication is done then next page is called up else the error page is thrown back.....

Now please give some suggestion...as I still not able to do it...
Thanks & regards,
Ravi

Ravi,

user_name=`echo $QUERY_STRING | awk -F"=" '{print $2}'`
Pass_word=`echo $QUERY_STRING1 | awk -F"=" '{print $2}'`

now search for user_name and password in the file as below.

ex: cat reference_file.txt

Name | Gender |Password
rohit|male|xxxx
robin|male|YYY

 
user_name="robin"
res1=`awk -F "|"  -v var_name=$user_name  '{if ($1==var_name){print "found";exit} }' reference_file.txt`

if res1 is "found" go and search the file again for password validation.