grep, but only certain file extensions

前端 未结 12 2492
野性不改
野性不改 2020-12-02 03:18

I am working on writing some scripts to grep certain directories, but these directories contain all sorts of file types.

I want to grep jus

12条回答
  •  Happy的楠姐
    2020-12-02 03:48

    If you want to filter out extensions from the output of another command e.g. "git":

    files=$(git diff --name-only --diff-filter=d origin/master... | grep -E '\.cpp$|\.h$')
    
    for file in $files; do
        echo "$file"
    done
    

提交回复
热议问题