Skip to main content
1 of 3
enzotib
  • 53.4k
  • 14
  • 126
  • 106

That of @rozcietrzewiacz is a great solution, but if you still want to stay with text files (as returned by file), you can carefully build an array of file names, then execute your grep command on that array. Here is a pseudo-example

#!/bin/bash

files() {
  local path="$1"
  find "$path" -type f -exec file --print0 --mime-type {} + |
    awk -F '\0' 'BEGIN { ORS = "\0" }; $2 ~ /text/ { print $1 }'
}

list=()
while read -d $'\0' line; do
  list+=("$line")
done < <(files .)

# to choose options and pattern
grep <options> <pattern> "${list[@]}"
enzotib
  • 53.4k
  • 14
  • 126
  • 106