What should I do when sed encounters a path?

Source: Internet
Author: User
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:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.