Skip to main content
Tweeted twitter.com/StackUnix/status/940726645337612289
added 584 characters in body
Source Link
Joe
  • 564
  • 4
  • 9

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) 

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?

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) 
Source Link
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?