What this template solves
This template is useful when the same URL path appears in config, docs, proxy rules, or client examples and needs to be rewritten consistently.
Sample input
https://api.example.com/v1/api/users
proxy_pass /v1/api;Prompt to start from
Replace /v1/api with /v2/api in the file
Expected command
sed 's#/v1/api#/v2/api#g'Tags
Best for
- Update API examples from one versioned path to another.
- Rewrite proxy routes after backend path changes.
- Replace repeated URL path fragments in docs or environment files.
How to use this template
- 1Identify the old path fragment and the new path fragment.
- 2Copy the sed replacement command that uses a path-friendly delimiter.
- 3Preview on sample input first, then apply the file-edit command on macOS or Linux.
Template FAQ
How do I replace a repeated URL path with sed?
A path-friendly delimiter such as `sed 's#/v1/api#/v2/api#g'` is a good starting point because it keeps the command readable and avoids over-escaping slashes in the path.
Where is a replace-url-path template most useful?
It works well in API documentation, reverse proxy rules, environment files, and client examples where the same route fragment appears on many lines and must change together.
Related templates
Explore nearby sed workflows that target similar replace, cleanup, filtering, or rewrite tasks.
Replace domain names
ReplaceReplace an old domain with a new one in bulk.
sed 's/old\.example\.com/new.example.com/g'Replace path prefixes
ReplaceReplace an old path prefix with a new one across many lines.
sed 's#/srv/legacy#/srv/current#g'Replace ports in bulk
ReplaceReplace every 8080 in a config with 80.
sed 's/8080/80/g'