I am trying to create a series of cross platform SED substitutions (Linux and MacOS) . I am getting two errors on MacOS for the two SED commands below which work fine under bash in Linux. What do I need to change to get them accepted under BSD style SED?
Note: In each command below, $sed_regex_sym is replaced with -r for Linux and -E for macOS.
sed -$sed_regex_sym "/.*[*]/!{/.*[|]{1}/s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]([_|\\\/])\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]/\3/g}"
sed -$sed_regex_sym "/^([[:space:]_|\\\/]{0,$N_HASH_CHARS})[A-Z][[:space:]]/s/([A-Z][[:space:]].{1,${N_STAT_CHARS_TO_KEEP}}).*/$(printf "%${N_STAT_INDENT_CHARS}s" " ")\1/"
For two commands above, I get the following two errors respectively:
sed: 1: "/.*[*]/!{/.*[|]{1}/s/\x ...": bad flag in substitute command: '}'
sed: 1: "/^([[:space:]_|\\/]{0, ...": RE error: invalid repetition count(s)
For the latter substitution, I did try escaping the parenthesis for the match groups as I saw on a another post but that did not resolve the invalid repetition count error.
Update 12/01/2018: I determined the source of the issues above. Going in reverse order:
1) The latter substitution was not actually a sed issue but instead, an earlier line in my script which executed wc ( word count ) to determine N_HASH_CHARS ended up with preceding spaces on macOS only. Trimming the spaces resolved the issues with the second sed command above
2) The first sed statement above was in fact a compatibility problem between BSD sed and Linux sed. I found elsewhere in stackoverflow the embedded function lists in BSD using { } need to have the internal function list end with a ;
Putting a ; just after the g for global substitution resolved the issue and works for both Linux and macOS
-E
for quite a while. – Benjamin W.