The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 07-17-2008
SAMZ SAMZ is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 18
Checking for certain characters

Could anyone help with the following enquiry.. i have a file in the following format:

ID .... VALUE
A001 .... 100
B002 .... 200
A004 .... 300
B006 .... 100
A997 .... 200
B776 .... 400

It is in a column format, but I want to check that the ID field always begins with with and A or B character this is my logic thus far:


If Character 1 DOES NOT equal A or B
then
display error message
else
carry on doing what you want
fi

not really sure how to chech that character 1 of each line does not equal A or B
habe tried following with no no joi

If [ ! grep '^A' $file || ! grep '^B' $file ] then
print "error"
else
print "it works"
fi

but the above does not work i believe it to logic as my unix understanding not great, please assist.