11
Only print field if it can be converted to an integer
If I have this sample text file
1 cat
2 dog
3 7
4 fish5
5 22
I want my awk script to only print the field if it can be converted to an integer.
I don't want rows 1,2 and 4 to be printed.
example awk script
BEGIN {
print "testing conversion to integer on " ARGV[1];
myinteger = 0; # my atmept to force this var to an integer
}
myinteger = $2;
myinteger != 0 { print $2; }
This doesn't work.
How can I get this to work?