I need to replace a specific part of a link
for example:
http://sub.somedomain.com/s/be2b46b4cb28ed64fe59d191cb600117/2013/image.jpg
to
http://sub.somedomain.com/s/123123/2013/image.jpg
what I've tried:
echo "http://sub.somedomain.com/s/be2b46b4cb28ed64fe59d191cb600117/2013/image.jpg" | sed "s@/s/(.+?)/@123123@g"
To replace a substring with new value in a string in Bash Script, we can use sed command. sed stands for stream editor and can be used for find and replace operation. We can specify to sed command whether to replace the first occurrence or all occurrences of the substring in the string.
Put a backslash before $. */[\]^ and only those characters (but not inside bracket expressions).
Regular expressions are used by several different Unix commands, including ed, sed, awk, grep, and to a more limited extent, vi.
sed "s@/s/[^/]*/@/s/123123/@g"
Problems with your regex:
(
and )
are regular characters in basic regular expressions (BRE) (and they are not really needed here)+
is also not special in BREsed -E
, you would match too much because you don't stop at the next slashIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With