I am trying to replace a string with a part in it. It works in CYGWIN on Windows machine but when I try it in MAc it gives me error.

WIN RESULT (works):
$ cat lastVersion.txt

$ sed -re 's/[0-9]+.[0-9]+.[0-9]+.([0-9]+).*/\1/' lastVersion.txt

MAC RESULT (does not work):
++ sed -e 's/[0-9]+.[0-9]+.[0-9]+.([0-9]+).*/\1/' lastVersion.txt
15:46:25 sed: 1: "s/[0-9]+.[0-9]+.[0-9] ...": \1 not defined in the RE

Any help? How can I make this work

I think this might be to do with the version of sed that you are using.

I think the default version of sed which ships with recent versions of the Mac OSes is based on the FreeBSD version, which doesn't contain the GNU extended regex syntax.
You could try using the -E switch to see if that works. Otherwise, perhaps you should consider installing GNU sed on your Mac!

Installing GNU sed might be the best option (either build and install from source, or install via homebrew/port). GNU sed is the version of sed you're already using under Cygwin on Windows. That way your original script will work on Windows, Linux and Mac without modification.

The only other option of course, would be to read the documentation for the version of sed which is installed on your mac, learn what regex syntax is supported and modify the Mac version of your script accordingly.

commented: Good suggestions. +12