use*_*191 2 regex shell perl insert paste
File1 Contents:
line1-file1 "1"
line2-file1 "2"
line3-file1 "3"
line4-file1 "4"
File2 Contents:
line1-file2 "25"
line2-file2 "24"
Pointer-file2 "23"
line4-file2 "22"
line5-file2 "21"
Run Code Online (Sandbox Code Playgroud)
执行perl/shell脚本后,
File 2 content should become
line1-file2 "25"
line2-file2 "24"
Pointer-file2 "23"
line1-file1 "1"
line2-file1 "2"
line3-file1 "3"
line4-file1 "4"
line4-file2 "22"
line5-file2 "21"
Run Code Online (Sandbox Code Playgroud)
即在包含行的"指针"之后,将文件1的内容粘贴到文件2中.
谢谢
使用r命令sed添加文本文件:
$ sed -i '/Pointer-file2/r file1' file2
$ cat file2
line1-file2 "25"
line2-file2 "24"
Pointer-file2 "23"
line1-file1 "1"
line2-file1 "2"
line3-file1 "3"
line4-file1 "4"
line4-file2 "22"
line5-file2 "21"
Run Code Online (Sandbox Code Playgroud)
使用r命令ed插入文本文件:
$ echo -e '/Pointer/-1r file1\n%w' | ed -s file2
$ cat file2
line1-file2 "25"
line2-file2 "24"
line1-file1 "1"
line2-file1 "2"
line3-file1 "3"
line4-file1 "4"
Pointer-file2 "23"
line4-file2 "22"
line5-file2 "21"
Run Code Online (Sandbox Code Playgroud)