zoukankan      html  css  js  c++  java
  • linux系统中sed命令 r参数在文件中直接插入文件

    1、测试数据如下:

    [root@centos79 test]# ls
    a.txt  b.txt
    [root@centos79 test]# cat a.txt
    3 4 5
    d g 3
    s g 8
    k s g
    2 5 d
    s c w
    a r t
    e 4 s
    [root@centos79 test]# cat b.txt
    Beijing 2003
    Beijing 2004
    Beijing 2005
    Beijing 2006
    Beijing 2007
    Beijing 2008

    2、在a.txt文件的第2行后插入b.txt文件

    [root@centos79 test]# cat a.txt
    3 4 5
    d g 3
    s g 8
    k s g
    2 5 d
    s c w
    a r t
    e 4 s
    [root@centos79 test]# cat b.txt
    Beijing 2003
    Beijing 2004
    Beijing 2005
    Beijing 2006
    Beijing 2007
    Beijing 2008
    [root@centos79 test]# sed '2r b.txt' a.txt
    3 4 5
    d g 3
    Beijing 2003
    Beijing 2004
    Beijing 2005
    Beijing 2006
    Beijing 2007
    Beijing 2008
    s g 8
    k s g
    2 5 d
    s c w
    a r t
    e 4 s

    3、在a.txt文件中匹配d的行后插入b.txt文件

    [root@centos79 test]# cat a.txt
    3 4 5
    d g 3
    s g 8
    k s g
    2 5 d
    s c w
    a r t
    e 4 s
    [root@centos79 test]# cat b.txt
    Beijing 2003
    Beijing 2004
    Beijing 2005
    Beijing 2006
    Beijing 2007
    Beijing 2008
    [root@centos79 test]# sed '/d/r b.txt' a.txt
    3 4 5
    d g 3
    Beijing 2003
    Beijing 2004
    Beijing 2005
    Beijing 2006
    Beijing 2007
    Beijing 2008
    s g 8
    k s g
    2 5 d
    Beijing 2003
    Beijing 2004
    Beijing 2005
    Beijing 2006
    Beijing 2007
    Beijing 2008
    s c w
    a r t
    e 4 s
  • 相关阅读:
    C#中关于zip压缩解压帮助类的封装(转)
    MonoTouch的官网
    Android布局
    VS2010网站发布
    HTML5的PLACEHOLDER属性
    some np problem
    srm 578
    opencv 边缘算子
    Python扩展(pybind11混编)
    PyTorch之初级使用
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14988740.html
Copyright © 2011-2022 走看看