0

I have the below url and trying to delete few string value and return the value in variable.

Input:

    https://ciapi-pilot22.us-central1.gcp.amazon.com/test-ci-1877/view/test/job/newFiJob

Expected output:

   /test-ci-1877/view/test/job/newFiJob

I tried the below command to eliminate the values and return the value into variable:

      test=$(echo "$resultTotalUrl" | sed 's/^https://ciapi-pilot22.us-central1.gcp.amazon.com/')
      echo $test

But it's failing.

ArrchanaMohan
  • 2,314
  • 4
  • 36
  • 84

1 Answers1

0

You need to handle characters that are the same as your delimiter existing in the string you're processing, in this case by escaping the slashes in the URL (or by using a different delimiter you're certain won't exist in your string), and you're missing a slash at the end of the sed command.

Your command should be (note https:// is now https:\/\/):

echo 'https://ciapi-pilot22.us-central1.gcp.amazon.com/test-ci-1877/view/test/job/newFiJob'| sed 's/^https:\/\/ciapi-pilot22.us-central1.gcp.amazon.com//'

Or (using a different delimiter, in this case ~)

echo 'https://ciapi-pilot22.us-central1.gcp.amazon.com/test-ci-1877/view/test/job/newFiJob'| sed 's~^https://ciapi-pilot22.us-central1.gcp.amazon.com~~'

See this link on sed usage and this link on sed delimiters for more info.

Max
  • 374
  • 1
  • 4
  • 10