Bash multiple files processing

前端 未结 5 1752
感动是毒
感动是毒 2021-01-23 19:21

I have a file named data_file with data: london paris newyork italy...50 more items

Have a directory with over 75 files, say dfile1, dfie2...afle75 in which i am perform

5条回答
  •  醉梦人生
    2021-01-23 20:01

    You could use grep's q option to stop searching after the first match and f option to obtain the patterns from a file:

    for f in $(find . -type f); do
        if $(grep -qf data_file "$f"); then
            ...
        fi
    done
    

    If data_file contains:

    xxx
    yyy
    zzz
    

    then grep -qf "$data_file" "$f" evaluates to true if either xxx, yyy, or zzz are found in $f.

提交回复
热议问题