【问题标题】:Extracting filenames containing one or more numbers then cat contents to output file提取包含一个或多个数字的文件名,然后将内容分类到输出文件
【发布时间】:2018-07-10 18:05:17
【问题描述】:

如果可能的话,我正在寻找一个 bash one 衬垫,它将文件夹中标记为 motif<number>.motif 的所有文件连接到一个 output.txt 文件中。

我有一些问题正在努力解决。

答:文件名中包含的<number> 可以是一位或两位数长,我不知道如何使用正则表达式(或类似的东西)来获取所有一位或两位数的文件。我可以使用以下方法分别获取包含一位或两位数字的文件名:

motif[0-9].motifmotif[0-9][0-9].motif

但不知道如何将所有文件放在一起。

B:我遇到的第二个问题是我不知道目录中有多少文件,所以我可以使用一个数字范围来选择文件。该命令位于一条长管道的中间。

假设我有 20 个文件夹:

motif1.motif motif2.motif ... motif19.motif motif20.motif

我需要将cat >> 的所有内容都写入output.txt

【问题讨论】:

    标签: regex linux bash numbers cat


    【解决方案1】:

    你可以这样做:

    cat motif{[0-9],[0-9][0-9]}.motif > output
    

    extglob:

    shopt -s extglob nullglob
    cat motif[0-9]?([0-9]).motif > output
    

    【讨论】:

    • 非常感谢@anubhava,这正是我想要的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    相关资源
    最近更新 更多