Reputation: 435
I am trying to change the following string
FROM java_jre_8@sha256:92f22331226b9b3c43a15eeeb304dd7
to
FROM docker-registry.service.consul:5000/java_jre_8@sha256:92f22331226b9b3c43a15eeeb304dd7
but am having difficult with sed as a result of /
character
This is for a build server.
Upvotes: 0
Views: 70
Reputation: 95958
You can use #
as the delimiter as it doesn't appear in your string (you can still use /
but then you'll have to quote the actual /
s that are part of the string).
sed "s#FROM java_jre_8@#FROM docker-registry.service.consul:5000/java_jre_8@#'
Example:
$ echo "FROM java_jre_8@sha256:92f22331226b9b3c43a15eeeb304dd7" | sed "s#FROM java_jre_8@#FROM docker-registry.service.consul:5000/java_jre_8@#"
FROM docker-registry.service.consul:5000/java_jre_8@sha256:92f22331226b9b3c43a15eeeb304dd7
Upvotes: 0
Reputation: 6387
There are two ways of doing this. The first is to escape each /
in the string you're replacing:
sed 's/from/to with \/ ... /'
The other, more simple way is to use a delimiter other than /
. While most sed examples use /
as a delimiter, you can use any character:
sed 's|from|to with / ...|'
Here, the |
is the first character following s
, and therefore sed knows to use this as a delimiter.
Upvotes: 1