zoukankan      html  css  js  c++  java
  • 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"}'
    

      

  • 相关阅读:
    MySQL锁
    mysql服务性能优化—my.cnf配置说明详解
    springmvc请求参数获取的几种方法
    Linux mysql 添加远程连接
    Linux 操作 mysql
    Linux 安装 mysql 转 http://www.cnblogs.com/fnlingnzb-learner/p/5830622.html
    linux 下 安装nginx
    dubbo 实战总结
    分布式事务的几种方式
    精巧好用的DelayQueue 转
  • 原文地址:https://www.cnblogs.com/qingxiaoping/p/13215314.html
Copyright © 2011-2022 走看看