代码之家  ›  专栏  ›  技术社区  ›  user2058738

approximate matching using grep

  •  0
  • user2058738  · 技术社区  · 7 年前

    我需要创建一个脚本,循环遍历目录中的文件,检查文件名是否在“list.txt”中,然后处理它。我的问题是,文件名是动态的,因为它有时间戳。

    有没有办法在unix中grep近似匹配?

    样品

    list.txt
    SAMPLE_REPORT_1
    SAMPLE_REPORT_2
    

    报告文件名

    SAMPLE_REPORT_1_20180416121345.csv
    SAMPLE_REPORT_2_20180416121645.csv
    

    我需要检查文件名是否在列表中。txt文件

    1 回复  |  直到 7 年前
        1
  •  0
  •   RomanPerekhrest    7 年前

    bash + grep 解决方案:

    for f in *.csv; do
        if grep -qx "${f%_*.csv}" list.txt; then
            # processing file $f 
        fi
    done