Replace

Replace path prefixes

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

What this template solves

This template is useful when a directory prefix changes and you need to rewrite repeated file paths in configs, scripts, or environment files.

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

Sample input

/srv/legacy/app
/srv/legacy/cache
keep=/srv/legacy/tmp

Prompt to start from

Replace /srv/legacy with /srv/current in the file

Expected command

sed 's#/srv/legacy#/srv/current#g'

Tags

replacepathsconfigmigration

Best for

  • Update deployment paths after moving a service directory.
  • Rewrite repeated mount paths in container or CI config.
  • Replace old filesystem prefixes in shell scripts and docs.

How to use this template

  1. 1Confirm the old path prefix and the new target prefix.
  2. 2Copy the replacement command with escaped path separators.
  3. 3Validate on sample input, then run the file-edit variant on the real file.

Template FAQ

How do I replace an old directory prefix across many paths with sed?

A path-friendly delimiter such as `sed 's#/srv/legacy#/srv/current#g'` is a common pattern because it avoids excessive escaping. This makes bulk path rewrites easier to read and safer to reuse.

What files usually need a replace-path-prefix workflow?

This workflow is common in deployment scripts, CI config, container setup, environment files, and migration docs where the same filesystem prefix appears on many lines.

Related templates

Explore nearby sed workflows that target similar replace, cleanup, filtering, or rewrite tasks.

Replace path prefixes Sed Template | AskSed