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

Was it helpful?

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top