This !@!@#@%
does not contain a-z
and its not 0
That is why you get hits on it.
To get only numbers, use anchor:
awk '/^[[:digit:]]+$/' file
123214
or
awk '/^[0-9]+$/' file
Question
I have command in awk
:
awk '$0 !~ /[a-z]/ && $0 != 0' input.txt >> output.txt
So my input is something like this:
123214
wedsd
sda25567
ssdf
!@!@#@%
And my output is:
123214
!@!@#@%
I think I am doing something wrong with awk
.
I want awk just show me digits, What should I do?
Thanks
Solution
This !@!@#@%
does not contain a-z
and its not 0
That is why you get hits on it.
To get only numbers, use anchor:
awk '/^[[:digit:]]+$/' file
123214
or
awk '/^[0-9]+$/' file
OTHER TIPS
try this:
awk '/^[0-9]+$/ && $0 != 0 {print}' input.txt >> output.txt