• sed 命令基础


    # sed 笔记
    一、替换[s]

    1. -e选项 sed -e 's/dog/DOG/;s/cat/CAT/' test.txt
    2. -f选项 sed -f sed.txt test.txt
    3. -n选项 sed -n sed 's/dog/DOG/' test.txt
    4. 数学方式行寻址 sed '2,3s/cat/CAT/' test.txt sed '3,$s/cat/CAT/' test.txt
    5. 模式过滤器 sed '/is dog/s/dog/DOG/' test.txt
    6. 命令组合 sed '2{s/dog/CAT/;s/pig/PIG/}' test.txt

    二、全局匹配[g]

    1. sed 's/dog/DOG/g' test.txt
    2. sed 's/dog/DOG/3' test.txt

    三、打印[p]

    1. sed 's/dog/DOG/p' test.txt
    2. sed -n '/line 4/{=;s/4/9p}' line.txt

    四、写入文件[w]

    1. sed 's/dog/DOG/w file.txt' test.txt

    五、删除[d]

    1. sed '2d' test.txt
    2. sed '2, $d' test.txt
    3. sed '/line 1/d' line.txt

    六、插入[i,a]

    1, sed '2i	his is insert line' line.txt
    2. sed '$a	his is insert line' line.txt

    七、修改[c]

    1. sed '2c	his is update line' line.txt
    2. sed '/line 4/c	his is update line' linet.txt

    八、转换[y]

    1. sed 'y/123/987/' line.txt

    九、文件读[r]

    1. sed '/line 3/r test.txt' line.txt
    2. sed '/line 3/{r test.txt;d}' line.txt

    # gawk 笔记
    一、 打印[print]

    1. gawk '{print "hello world"}'
    2. gawk -F: '{print $1 "home is " $6}' /etc/passwd
    3. gawk -F: -f test.awk /etc/passwd
    4. gawk -F: '{$1=leng;print $0}' /etc/passwd

    二、处理前后[BEGIN:END]

    1. gawk 'BEGIN {print "this is file content"} {print $0} END{print "end file"}'
    

      

  • 相关阅读:
    DDT驱动selenium自动化测试
    python 对Excel表格的读取
    python 对Excel表格的写入
    selenium对百度进行登录注销
    selenium的八大定位元素的方式
    selenium打开Chrome浏览器并最大化
    行列式计算的归纳
    C标准库函数getchar()
    测试必备-抓包工具的使用
    uiautomator2使用教程
  • 原文地址:https://www.cnblogs.com/qingxiaoping/p/13215314.html
Copyright © 2020-2023  润新知