0

我想使用命令 linux 粘贴两个文件paste(也欢迎任何其他选项)但增加第二个文件的行。最好举个例子:

文件 1

a
b
c
d
e
f

文件2

1
2
3
4
5
6
7
8
9
10
11
12

我想创建 file3 为:

a 1
b 3
c 5  
d 7
e 9
f 11
4

1 回答 1

5

用于仅awk打印文件二中的奇数行:

$ awk 'NR%2' file2 | paste -d' ' file1 -
a 1
b 3
c 5
d 7
e 9
f 11

# Using process substitution 
$ paste -d' ' file1 <(awk 'NR%2' file2)
a 1
b 3
c 5
d 7
e 9
f 11
于 2013-03-15T08:55:28.417 回答