[英]awk pattern is matching the wrong numbers
My script does this 我的脚本这样做
ls -1A | awk '/model[1-9]+.dat/' | while read FN
but when I increase model[1-9] to model[1-1000], it doesn't match the files I expect. 但是当我将模型[1-9]增加到模型[1-1000]时,它与我期望的文件不匹配。
when increase model[1-9] to model[1-1000] its taking random number 当增加模型[1-9]到模型[1-1000]时,其取随机数
likes model100.dat, model105.dat. 喜欢model100.dat,model105.dat。 model11.dat ...etc model11.dat ...等
No, it's not random. 不,不是随机的。
[1-1000]
doesn't mean "any number from 1 to 1000". [1-1000]
并不表示“ 1到1000之间的任何数字”。 It means a number between 1 and 1, or 0, or 0, or 0. Which is simply 0 or 1. Which is obviously not what you meant. 它表示1到1之间的一个数字,或者0或0或0之间的数字。简单来说就是0或1。这显然不是您的意思。
If you want to look at only the first 1000 files, you can make a pattern that says the file name must have one digit [0-9]
, two digits [0-9][0-9]
, or three digits [0-9][0-9][0-9]
. 如果只想查看前1000个文件,则可以创建一个模式,说明文件名必须包含一个数字[0-9]
,两个数字[0-9][0-9]
或三个数字[0-9][0-9][0-9]
。 Put |
放|
between each one to mean "or". 彼此之间的意思是“或”。 So it is written ([0-9]|[0-9][0-9]|[0-9][0-9][0-9])
. 因此它被写入([0-9]|[0-9][0-9]|[0-9][0-9][0-9])
。 This means 0-999. 这意味着0-999。
Then you can change your awk part to 然后您可以将awk部分更改为
awk '/^model([0-9]|[0-9][0-9]|[0-9][0-9][0-9])\.dat$/'
您完全不需要awk,bash括号扩展就足够了。
for filename in model{1..1000}.dat; do ...; done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.