regex - Find and replace strings in file with $ selectors? -
i have file , i'm looking use ()
select piece of text, , $1
, $2
respectivley replace string.
http://127.0.0.1:5080/tarballs/(.+)/(.+).tgz https://registry.npmjs.org/$1/-/$1-$2.tgz
how can in unix? want run command this:
$ regex-replace ./file.txt "http://127.0.0.1:5080/tarballs/(.+)/(.+).tgz" "https://registry.npmjs.org/$1/-/$1-$2.tgz"
you can use sed
:
s='http://127.0.0.1:5080/tarballs/user/file.tgz' sed -e 's~http://127\.0\.0\.1:5080/tarballs/(.+)/(.+.tgz)$~https://registry.npmjs.org/\1/-/\1-\2~' <<< "$s" https://registry.npmjs.org/user/-/user-file.tgz
- dot special metacharacter in regex needs escaped, otherwise match character.
~
used regex delimiter ins
(substitute) command ofsed
.-e
used extended regex support.\1
,\2
back-references of 2 captured groups.
Comments
Post a Comment