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
  • 相关阅读:
    Telnet远程测试
    数据库笔记
    gcc 链接不到 函数实现, undefined reference to xxx
    usb2ttl 引脚定义
    ip v4 地址中 局域网地址范围
    vdi 磁盘文件转换为 vmdk文件的命令
    tftp 命令使用
    无法通过vnc连接到局域网内的树莓派
    镜像服务网站
    C语言 scanf 输入浮点数的用法
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14988740.html
Copyright © 2011-2022 走看看