Problem with Regular expression in awk

Hi,
I have a file with two fields in it as shown below

14,30
28,30
16,30
22,30
21,30
3,30

Fields are separated by comma ",".
I've been trying to validate the file based on the condition "each field must be a numeric value"

I am using HP-UX OS.

I have tried the following awk commands but none works.

echo "14,14" | awk -F"," '$1 != /[:digit:]/ || $2 != /[:digit:]/ {a=1;} END{if(a==1) print "Error in file descriptor file";}'
echo "14,14" | awk -F"," '$1 != /[[:digit:]]/ || $2 != /[[:digit:]]/ {a=1;print $0;} END{if(a==1) print "Error in file descriptor file";}'
echo "14,14" | awk -F"," '$1 !~ /^[1-9]*$/ || $1 ~ /^$/ || $2 !~ /^[1-9]*$/ || $2 ~ /^$/ {a=1;} END{if(a==1) print "Error in file descriptor file"}'

The above commands are displaying the error message even if the file is in the correct format.
Please help me on this.

$ cat file
3,30
16,y
x,30
$ awk -F "," '$1 !~ /[[:digit:]]/ || $2 !~ /[[:digit:]]/ { print "Line " NR ": " $0 }' file
Line 2: 16,y
Line 3: x,30

You were close. It's good you tried first. BTW, here is another way. Not sure which is "better":

$ grep -v -n "^[[:digit:]]\+,[[:digit:]]\+$" file
2:16,y
3:x,30
1 Like
$ cat file
14,30
28,30
16,30
22,30
21,30
3,30
28,f
ff,25
ff,ss
$ awk '!/^[0-9]+,[0-9]+/{print NR,$0}' file
7 28,f
8 ff,25
9 ff,ss
1 Like

Using pamu's file and based on his approach:

$ awk '!/^[,0-9]*$/ {print NR,$0}' file
7 28,f
8 ff,25
9 ff,ss
2 Likes

try with nawk

$ awk -F, '$1+0!=0 && $2+0!=0' a.txt
14,30
28,30
16,30
22,30
21,30
3,30
$ echo "A,B" >> a.txt
$ echo "1,3" >> a.txt
$ cat a.txt
14,30
28,30
16,30
22,30
21,30
3,30
A,B
1,3
$ awk -F, '$1+0!=0 && $2+0!=0' a.txt
14,30
28,30
16,30
22,30
21,30
3,30
1,3
$ awk -F, '$1+0==0 || $2+0==0{print "Not a valid file";exit}' a.txt
Not a valid file