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
  • 相关阅读:
    I firmly believe
    深度学习常见的专业术语
    阿里、网易和腾讯面试题 C/C++
    Winfrom中关于toolStrip工具栏中按钮背景的设置
    非常完善的Log4net详细说明
    C#中 Var关键字
    C#中Dynamic关键字
    Python中threading的join和setDaemon的区别[带例子]
    pycharm常用快捷键
    ABP发布到iis
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14988740.html
Copyright © 2011-2022 走看看