从文件中打印数字,从x到y [英] Print numbers from file, from x to y
本文介绍了从文件中打印数字,从x到y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数字从-100到100的文件,我只想打印从-10到10
目前,我在
p> egrep'[0-9] [0-3]'
不幸的是,它会打印-13,-12,-11,-10,10,11,12,13,20,21,22,23。
解决方案
试试这个正则表达式:
^ [ - ]?(10 | [0-9])$
在CLI上调用会是:
pre $ code egrep^ [ - ]?(10 | [0-9])$testfile
为什么
- 先选择一个可选的前导 -
- ,然后加上:
- 文字数字10或
- 0至9之间的单个数字
- ,而后面没有任何东西
I've got a file with numbers from -100 to 100, I only want to print from -10 to 10
Currently, I'm at
egrep '[0-9][0-3]'
Which, unfortunately, prints -13, -12, -11, -10, 10, 11, 12, 13, 20, 21, 22, 23.
解决方案
Have a try with that regular expression:
^[-]?(10|[0-9])$
So the call on CLI would be:
egrep "^[-]?(10|[0-9])$" testfile
Why?
- start with an optional leading "-"
- followed by either:
- literal number "10" or
- single digit between 0 and 9
- and nothing behind that
这篇关于从文件中打印数字,从x到y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文