user7649922
user7649922

Reputation: 623

sed command help. How to substitute a key word for the full path of the current working directory

I'm currently using the 'sed' command (below) which searches for the word {{Title}} and replaces it with the current working directory ${PWD##*/}/.

sed -i "s/{{Title}}/${PWD##*/}/g" filename.x

How do I modify the above 'sed' command to work for the full path of the current working directory?

Any help will be much appreciated!

Upvotes: 1

Views: 76

Answers (1)

Grisha Levit
Grisha Levit

Reputation: 8617

Change the s command to use a separator that is not part of the path. Generally, : is not allowed in path names so it's safe to use here instead of /, like instead of:

s/expression/$PWD/

use

s:expression:$PWD:

Upvotes: 1

Related Questions