zoukankan      html  css  js  c++  java
  • linux系统中常用的转义字符 \、" "、' '、` `。

    1、创建测试数据

    [root@linuxprobe test]# echo "aaa.bbb.ccc.ddd" > a.txt
    [root@linuxprobe test]# cat a.txt
    aaa.bbb.ccc.ddd

    2、利用\进行转义,使转义字符仍为字符串

    [root@linuxprobe test]# sed 's/./ /' a.txt ## 利用sed命令进行替换,将.替换为空格, .没有转义前表示任意字符,仅第一个a被替换为空格
     aa.bbb.ccc.ddd
    [root@linuxprobe test]# sed 's/\./ /' a.txt ## 加转义字符\,.为普通字符串,被替换为空格
    aaa bbb.ccc.ddd
    [root@linuxprobe test]# sed 's/\./ /g' a.txt ## 加g表示全局替换,所有的.都被替换为空格
    aaa bbb ccc ddd

    3、' '将变量保持为普通字符串," "保持变量的原有属性

    [root@linuxprobe test]# ls
    a.txt
    [root@linuxprobe test]# cat a.txt
    aaa.bbb.ccc.ddd
    [root@linuxprobe test]# x=5  ##自定义变量 x等于5
    [root@linuxprobe test]# echo $x  ##查看变量
    5
    [root@linuxprobe test]# sed 's/b/$x/g' a.txt  ## ' '将变量保持为普通字符串,所有的b被替换为$x
    aaa.$x$x$x.ccc.ddd
    [root@linuxprobe test]# sed "s/b/$x/g" a.txt ## " " 保持变量原有属性,所有的b被替换为5
    aaa.555.ccc.ddd

    4、` ` 表示返回命令执行后的结果

    [root@linuxprobe test]# for i in `seq 5`;do echo $i;done  ## 将seq 5执行的结果返回给变量i
    1
    2
    3
    4
    5
    [root@linuxprobe test]# ls
    a.txt
    [root@linuxprobe test]# find *
    a.txt
    [root@linuxprobe test]# find * | sed "s#^#`pwd`/#"  ## 在a.txt文件前加绝对路径,利用sed在a.txt前添加pwd执行后的结果
    /home/linuxprobe/data/sheepreq/fasta/test/test/a.txt
  • 相关阅读:
    django用户认证系统——基本设置1
    django用户认证系统——注册3
    django数据库设计
    修改linux最大文件句柄数
    LoadRunner监控Linux
    MySQL设置密码的三种方法
    JMeter学习-021-JMeter 定时器的应用
    mysql-bin.000001文件的来源及处理方法【转】
    js读取解析JSON数据
    关于查询区域标注区域总结
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13769806.html
Copyright © 2011-2022 走看看