We know that the general sed Text Replacement Command & amp; 26684; formula is as follows: sed-e & quot; soriginnewg & quot; inputtxt but what should we do when we replace or replace something that is not like origin or new but a path? The answer is escape !! For example, I have the following in
We know that the general sed text replacement command format is as follows:
Sed-e "s/origin/new/g" input.txt
But what if we want to replace or replace something that is no longer like origin or new, but a path?
The answer is escape !!
For example, I have the text of input.txt.
1. set path VARPATH running workspace.2. runing this program
I want to replace VARPATH with/var/tmp/cloud, and use shell scripts to implement the following:
! /Bin/sh
######################################## ###################
# Sedpath. sh
# This script is used to deal with sed replace with path
######################################## ###################
VARPATH = "/var/tmp/cloud"
VARPATHSED =$ (echo $ {VARPATH} | sed-e's/\ // \\///g ')
Echo "origin content :"
Echo "-----------------"
Cat input.txt
Echo "-----------------"
Echo "VARPATH =$ {VARPATH }"
Echo "VARPATHSED =$ {VARPATHSED }"
Cat input.txt | sed-e "s/VARPATH/$ {VARPATHSED}/g"> output.txt
Echo "the result content :"
Echo "-----------------"
Cat output.txt
Echo "-----------------"
The running result is as follows: