Replace

Replace URL paths

Replace an old URL path segment with a new one across many lines.

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.

Open the workspace with this template preloaded, then refine it for your own file and text pattern.

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

replaceurlspathsapi

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

  1. 1Identify the old path fragment and the new path fragment.
  2. 2Copy the sed replacement command that uses a path-friendly delimiter.
  3. 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 URL paths Sed Template | AskSed