简体   繁体   中英

Replacing text at end of string via command line based on beginning of string

Given the below json example - how would I replace the 7 characters with a different string after the hash for module2 from a unix command line?

{
 "module": "git+https://9gke37d40a7a9f84659e98f386d4ea2fda2a5d86:x-oauth-basic@github.com/org-name/repo.git#71e84fd",
 "module2": "git+https://9gke37d40a7a9f9999e98f386d4ea2fda2a5d86:x-oauth-basic@github.com/org-name/repo.git#99h43ae",
 "module3": "git+https://9gke37d40a7a9f33759e98f386d4ea2fda2a5d6:x-oauth-basic@github.com/org-name/repo.git#94i53bb"
}

If you have the above lines, you could do

sed -i -e 's/(.*module2.*?#)(.......)(.*)/\1abcdefg\3/' json-file

where abcdefg would be your replacement string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM