質問

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

役に立ちましたか?

解決

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

他のヒント

try this:

awk '/^[0-9]+$/ && $0 != 0 {print}' input.txt >> output.txt
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top