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