zoukankan      html  css  js  c++  java
  • Sed basic and practice

    定义:Sed 是针对数据流的非交谈式编辑器,它在命令行下输入编辑命令并指定文件,然后可以在屏幕上看到编辑命令的输出结果。

    好处:Sed 在缓冲区内默认逐行处理数据,所以源文件不会被更改和破坏。

    格式:Sed ‘command' filename

    原理:Sed 用数字或规则表达式在定位编辑的地址,然后Command告诉Sed如何处理该行。可以打印,删除,或者更改。

    #/bin/bash
    echo 'here is a sed script'
    echo '======= print the content of employees'
    cat employees
    echo '======= delete line1 to 3 and print'
    sed '1,3d' employees
    #delete line include frank
    sed '/frank/d' employees
    #delete line unclude frank
    sed '/frank/!d' employees
    #print frank line and all line
    sed '/frank/p' employees
    #print frank line only
    sed -n '/frank/p' employees
    #delete line4 to end and print
    sed '4,$d' employees
    #delete last ine and print
    sed '$d' employees
    #delete line including john and print
    sed '/john/d' employees
    #replace all john to hello
    sed 's/john/hello/g' employees
    #replace all john to hello and print replaced only
    sed -n 's/john/hello/gp' employees
    #print replaced line only
    sed -n 's/^john/hello/p' employees
    #replace nn to nn.5 and print
    sed 's/[0-9][0-9]$/&.5/' employees
    #print replaced line only
    sed -n 's/[0-9][0-9]$/&.5/p' employees
    #print from eric to mark
    sed -n '/eric/,/mark/p' employees
    #print line1 to mark
    sed -n '1,/^mark/p' employees
    #delete line and replace
    sed -e '1,3d' -e 's/frank/huma/' employees
  • 相关阅读:
    spring源码学习(一) 小小少年
    mysql索引 小小少年
    Java集合框架个人学习笔记 小小少年
    记录一些自己百度到的问题解决方法
    基于内容的医学图像总结
    黑客与画家 第一章
    问题,不是逃避的
    黑客与画家 第二章
    记录最近一周的感受
    暗时间之体会
  • 原文地址:https://www.cnblogs.com/oskb/p/3337045.html
Copyright © 2011-2022 走看看