Hi I have one script that was running inside makefiles for project deployments. I use sed inside it to capture environment and project name from input string and in ubuntu works great.
This simple command
echo deploy-api-production | sed -E 's/deploy-\w+-(\w+)/\1/'
gives expected result production
in ubuntu
ubuntu execution
$ echo deploy-api-production | sed -E 's/deploy-\w+-(\w+)/\1/'
production
but in mac gives the entire full string deploy-api-production
mac execution:
$ echo deploy-api-production | sed -E 's/deploy-\w+-(\w+)/\1/'
deploy-api-production
Is there some kind of unified sed so I get same result in mac as well?
I want output to be only production in mac execution as well
Case 2 - more generic, including prefix as well
Want to parse this properly
echo a-deploy-api-production | someprocessing
production
So is similar to above case, but does has one extra prefix word a-
before the word deploy
I tried something similar to current given solution but did not work
echo a-deploy-api-production | awk -F'-' '$1=="a-deploy"{print $3}'
result of above is empty, want to modify to get result production
\w
nor+
are POSIXsed
.\w
is[[:alnum:]]
; the portable form of+
is{1,}
(one or more occurences). So your litetal command issed -E 's/deploy-[[:alnum:]]{1,}-([[:alnum:]]{1,})/\1/'
. But in the end, it seems you are looking forsed '/deploy-/s/.*-//'