RegEx:如何获取包含13到20小时的文件名
我想获取文件名,该文件名包含13到20之间的小时数 我有下面的文件夹中的文件RegEx:如何获取包含13到20小时的文件名,regex,bash,Regex,Bash,我想获取文件名,该文件名包含13到20之间的小时数 我有下面的文件夹中的文件 $ ls A_13_a.txt A_14_a.txt A_17_a.txt A_20_a.txt A_21_a.txt 其中数字表示小时 我想执行这个命令,它将返回到name下面 A_13_a.txt A_14_a.txt A_17_a.txt A_20_a.txt 我尝试了下面的命令,但没有给出正确的输出 ls | egrep 'A_[1][3-9]_a.txt | A_[2][0-0]_a.txt
$ ls
A_13_a.txt A_14_a.txt A_17_a.txt A_20_a.txt A_21_a.txt
其中数字表示小时
我想执行这个命令,它将返回到name下面
A_13_a.txt A_14_a.txt A_17_a.txt A_20_a.txt
我尝试了下面的命令,但没有给出正确的输出
ls | egrep 'A_[1][3-9]_a.txt | A_[2][0-0]_a.txt'
ls | grep 'A_[1][3-9]_a.txt'
您需要将要解析为文字点的点转义,并使用交替组
(1[3-9]| 20)
和egrep
,如下所示:
ls | egrep 'A_(1[3-9]|20)_a\.txt'
^^^^^^^^^^ ^
(1[3-9]| 20)
与以下两种备选方案中的任何一种匹配:
-1[3-9]
后跟从1
到3
9
-或|
-文字字符序列20
20
ls | awk -F_ '{ if ( $2 > 12 && $2 < 21 ) print $0 }'
ls | awk-F'{if($2>12&&$2<21)打印$0}'
Tryls | egrep'A_1[3-9]| 20)A\.txt'
No,我已经试过了,这是一个空白输出。尝试使用egrep
并逃出dot.woooooo,现在可以工作了,非常感谢。