Skip to main content
edited tags
Link
Ed Morton
  • 35.8k
  • 6
  • 25
  • 60
added 213 characters in body
Source Link

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

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

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

Source Link

How to use crossplatform/standard sed between linux and mac?

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