How to check if the first character of a string is a number using awk. I tried below but I keep getting syntax error.
awk ' { if (substr($1,1,1) == [0-9] ) print $0 }' da.txt
I suggest using @ hek2mgl's solution. I have pointed out some of the problems.
Problems:
/..regex../
~
==
Really:
awk '{ if (substr($1,1,1) ~ /^[0-9]/ ) print $0 }' file.txt
I would use regex instead substr() . This will do the trick:
substr()
awk '$1 ~ /^[[:digit:]]/' da.txt
Note that I am omitting print $0 as this is the default action in awk .
print $0
awk