Question: Can someone help me with a relatively complex command-line file matching pattern?

I've got files in a directory as follows:

```
1.png
1_thumb.png
1-1.png
1-1_thumb.png
1-2.png
1-2_thumb.png
2.png 
2_thumb.png
2-1.png
2-1_thumb.png
3.png
3_thumb.png
3-1_thumb.png

```

I want to list all the files that don't have a copy with the same filename with `-1` somewhere in it. So, in the example above, the results would be `3.png`. 

NB: the file and its copy with "-1" in it will be the same filesize, if that helps. 

Can anyone suggest how to do this?

Answer: 
Assuming that all files with `-n` is a copy and that you don't want the thumbs either, this works in KornShell (ksh), and also in Bash with the `extglob` option set (`shopt -s extglob`):

```
for f in !(*_thumb.png|*-[1-9].png); do
  g=${f%.png}-1.png
  test -f $g || echo $f
done

```
If it's only "-1" that determines it's a copy, then you have no copy of your 2-1.png
or 2-1\_thumb.png files either. If that's your matching criteria and you want the thumbs tested as well, you can do

```
for i in `ls |grep -v "\-1"  | cut -f1 -d.`; do 
    if `echo $i | grep thumb > /dev/null`; then 
        test -f `echo $i.png | sed 's/_/-1_/g'` || echo $i.png; 
    else 
        test -f $i-1.png || echo $i.png; 
    fi; 
done

```

Otherwise, if the thumbs don't count, KAKs answer should suit