-1

I have an XML document that has entries that contains URL, basically a Git / Bitbucket URL:

<value>
https://git...com/projects/.../..._config.json?raw&amp;at=dev
</value>

So basically this URL points to the dev branch, and I want to replace it such that it points to master by removing the "&amp;at=dev" string.

How do I trim this using regex using the suffix "_config.json?raw" as reference? Can you give both Python and bash script solution? How about when "at=dev" is to be replaced with "at=release"? (Please note that I cannot just replace all occurence of "dev" as the word is too common, so I still need to use "_config.json?raw" as regex reference)

oikonomiyaki
  • 7,691
  • 15
  • 62
  • 101

1 Answers1

0

with sed

sed -E 's/(config.json\?raw)&amp;at=dev\b/\1/' file

note that you have to escape the question mark.

karakfa
  • 66,216
  • 7
  • 41
  • 56
  • What's the difference between `sed -e` and `sed -E`? I'm trying to use `sed -i` to modify the file but I get some error. Same error results from `sed -e`. `invalid reference \1 on 's' command's RHS` – oikonomiyaki Feb 27 '18 at 04:06
  • they are different options. `-E` is to enable regex for `\1` substitution. Perhaps try `-r` instead. – karakfa Feb 27 '18 at 04:10
  • @menorah84 see https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux and https://stackoverflow.com/questions/24275070/sed-not-giving-me-correct-substitute-operation-for-newline-with-mac-difference/ – Sundeep Feb 27 '18 at 05:00