Skip to main content
2 of 2
added 584 characters in body
Joe
  • 564
  • 4
  • 9

List files not having another file with suffix

Consider a directory with the following files:

file1 file1.suffix file2 file3 file3.suffix 

I need to list all files such that there doesn't exist another file having the same name and a known suffix. In the example above that would match only file2.

This is what i came up with:

diff --new-line-format= --unchanged-line-format= \ <(ls -I '*.suffix' | sort) \ <(ls *.suffix | sed 's/\(.*\)\.suffix/\1/' | sort) 

Is there a simpler and shorter way?

Edit 1

In my concrete case there's actually multiple suffixes (bind zone files /w dnssec):

example.org example.org.jbk example.org.jnl example.org.signed example.org.signed.jnl example.com 

I'm trying to list zones that don't have dnssec enabled, that is, files that don't have another file with .signed extension.

This is my attempt:

diff --new-line-format= --unchanged-line-format= \ <(ls -I '*.jbk' -I '*.jnl' -I '*.signed' -I '*.signed.jnl' | sort) \ <(ls *.signed | sed 's/\(.*\)\.signed/\1/' | sort) 
Joe
  • 564
  • 4
  • 9