Bash – All files in a directory that do not end in a specific string

bashshellzsh

I want to find all text files in a directory that do not end with the string:

hello world

How can I do this?

Best Answer

Try:

for f in *; do
  if [ -f "$f" ] && [ "$(tail -n1 -- "$f")" != "hello world" ]; then
      printf '%s\n' "$f"
  fi
done
Related Question