0

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
4.2.1.98/

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

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

2
Contributors
1
Reply
21
Views
4 Years
Discussion Span
Last Post by JasonHippy
1

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.

Edited by JasonHippy

Votes + Comments
Good suggestions.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.