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
awk
to test the content of a shell variable? Can you identify your shell, as there may be other possibilities. Apart from that, please add the failingawk
program and the exact command line you used to call it. – AdminBee Mar 12 '21 at 10:26/^[A-Za-z]+$/
? Or, for greater readability,/^[[:alpha:]]+$/
– steve Mar 12 '21 at 10:41:alpha
covers Unicode, e.g. matchesÐ
. – steve Mar 12 '21 at 10:50