Artificial intelligent assistant

How to use regex to test variable in awk? I want to test if a script argument is only composed of letters. here is the script : BEGIN { VALUE=ARGV[1]; if (VALUE ~ /[A-Za-z]/) { print VALUE " : Ok only letters"; } print VALUE; } it seems that it matches every string with at least one letter : tchupy@rasp:~$ awk -f s.awk file 111 value = 111 tchupy@rasp:~$ awk -f s.awk file @@@ value = @@@ tchupy@rasp:~$ awk -f s.awk file aaa aaa : Ok only letters value = aaa tchupy@rasp:~$ awk -f s.awk file 1a1 1a1 : Ok only letters value = 1a1 tchupy@rasp:~$ awk -f s.awk file a1a a1a : Ok only letters value = a1a tchupy@rasp:~$ awk -f s.awk file 1@1 value = 1@1 I tried to use the _match()_ function, but I've got _a syntax error at or near [_ when I try to use [A-Za-z] regex. Thx

Your test will be true if the variable contains at least one character from your character class. To test if the variable _only_ contains characters in your character class, you need to match from the beginning (`^`) to the end of the script:


BEGIN {
VALUE=ARGV[1];
if (VALUE ~ /^[A-Za-z]+$/) {
print VALUE " : Ok only letters";
}
print VALUE;
}


Or more concisely:


BEGIN {
print ARGV[1] ": " (ARGV[1] ~ /^[A-Za-z]+$/ ? "OK" : "BAD")
}

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 38185e138355fa288867df3dd9eadbac