Use the SED command in the shell to replace/\/

Source: Internet
Author: User

SED command Related:

Https://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856901.html

Https://www.cnblogs.com/DragonFire/p/6600121.html

Here we have to do the function is:

Enter a directory "/data/data8"

Transform it to "\/data\/data8" in the shell (this is to be used directly in the SED command behind the shell)

Let's take a look at how the direct use command is implemented:

Echo "/data/data8" |sed ' s/\//\\\//g '

' s/\/\\\//G ': s represents the substitution of G for the end of the line, three marked black magnified "/" is the character that splits the substitution rule and replaces the result, "\" represents the escape character

If you want to pass in a parameter in the Shell's sed command, you should wrap it in double quotes

Some of the differences in the shell, mainly is a few more escape characters, please understand, the shell code is as follows

Temp= 'echo $1|sed ' s/\//\\\\\//g 'echo $temp

Execution Result:

[Email protected] testshell]#/testtext.sh  /data/d\/data\/d

Use the SED command in the shell to replace/\/

Related Article

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.