使用 grep 进行近似匹配

approximate matching using grep

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

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

样本。

list.txt
SAMPLE_REPORT_1
SAMPLE_REPORT_2

报告文件名

SAMPLE_REPORT_1_20180416121345.csv
SAMPLE_REPORT_2_20180416121645.csv

我需要检查文件名是否在 list.txt

bash + grep 解法:

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