Remove last string from each line

I am trying to write a script that will allow me to recursively look at my directories, and output all filenames to a txt document. I am almost finished, however I am hitting one last snag. Here is my script so far:

find . | grep .jpg | awk -F"/" '{print $NF}' > output.txt

This will give me an output like this:

IMG_059 - Wife - 2009 - Vegas.jpg
IMG_0001 - 2011 - Hawaii.jpg
IMG_0002 - Me - 2011 - Hawaii.jpg

My goal is for this list to look like this:

IMG_059 - Wife - 2009
IMG_0001 - 2011
IMG_0002 - Me - 2011

What code can I add so that everything after the final " - " is removed?

FYI check out the basename and dirname commands
New command with some extra commands for find

find . -name '*.jpg' -exec basename {} \; | awk -F '-'  '{for(i=1;i<NF;i++ {printf("%s ", $i)}; print "" }' > output.txt

Thanks for the heads up about basename and dirname commands. Your script is much more streamlined.

When I run your command, I get a bunch of errors:
awk: cmd. line:1: {print $(NF)
awk: cmd. line:1: ^ unexpected newline or end of string
find: `basename' terminated by signal 13
find: `basename' terminated by signal 13
find: `basename' terminated by signal 13
find: `basename' terminated by signal 13
....

Thoughts?

You could also pipe it through sed:

find . -name "*.jpg" | sed 's!.*/!!; s/-[^-]*$//' >output-file

Agama - thanks for the reply. That works!

There are so many different ways to get to the same answer. I'm learning a lot... both these scripts are way more efficient than anything I was attempting to write. I appreciate the help.

Didn't see your post when I posted before. The awk is missing a paren:

awk -F '-'  '{for(i=1;i<NF;i++ ) {printf("%s ", $i)}; print "" }

It should work if you add that.

Better yet than using '-exec basename {}' would be to use the -printf of find(1):

find . -name '*.jpg' -printf "%f\n" | awk ...

Pipe it to Perl.

perl -lne '/(.*) -.*/;print $1'