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