在linux中你可以将一个文件复制到特定行的另一个文件中(使用终端命令)吗?
实施例
文件1:
this is
file 1
文件2:
this is
file 2
新文件:
this is
this is
file 2
file 1
答案 0 :(得分:1)
您可以使用paste
$ cat file1
this is
file 1
$ cat file2
this is
file 2
$ paste -d '\n' file2 file1 > new_file
$ cat new_file
this is
this is
file 2
file 1
答案 1 :(得分:0)
我认为没有任何本地命令可以执行此操作,但您至少可以通过两种方式执行此操作。
1a. file chunk1 = head _n_ lines of file 1
1b. file chunk2 = tail _m_ lines of file 1
1c. cat chunk1 file_2 chunk2 > new_file
或写一个简单的脚本(例如,在Perl中)到
2a. read _n_ lines of file 1 and write them out to new_file
2b. read file 2 and write it out to new_file
2c. finish reading remaining lines of file 1 and write them out to new_file
答案 2 :(得分:0)
head --lines=$NLINES input1 >output
"输出第一个$NLINES
cat input2 >>output
"插入第二个文件tail --lines=+$[NLINES+1] input1 >>output
"输出剩余的行