RegEx:如何获取包含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

我想获取文件名,该文件名包含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 | 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}'

Try
ls | egrep'A_1[3-9]| 20)A\.txt'
No,我已经试过了,这是一个空白输出。尝试使用
egrep
并逃出dot.woooooo,现在可以工作了,非常感谢。