sed - Bash: How to Remove Multiple Prefix Variants From a String -


i'm trying remove prefix of url string parsed package.json file using bash. issue found not enters repository:url consistently in package files.

e.g.:

git+https://github.com/<user>/<repo>.git

https://github.com/<user>/<repo>.git

and have found:

http://github.com/<user>/<repo>.git

so question is, how remove either string prefix might found in .json? below unsuccessful attempt.

repo_url="`node -pe 'json.parse(process.argv[1]).repository.url' "$(cat $pkg_json)"`"  repo=${repo_url#git+} repo=${repo_url#https://github.com/} repo=${repo%.git} echo "${repo}" 

update:

i discovered adding wildcard before prefix eliminate before , including prefix. how handle http?

e.g.:

repo=${repo_url#*https://github.com/} 

each of assignments repo uses original $repo_url source, removals previous assignment aren't maintained. should use $repo source, except first one:

repo_url="`node -pe 'json.parse(process.argv[1]).repository.url' "$(cat $pkg_json)"`"  repo=${repo_url#git+} repo=${repo#https://github.com/} repo=${repo%.git} echo "${repo}" 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -