【问题标题】:how to paste two files (columns) to a third file incrementing line+1?如何将两个文件(列)粘贴到第三个文件递增行+1?
【发布时间】:2013-03-15 17:00:10
【问题描述】:

我想使用命令 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

【问题讨论】:

  • 每行之间真的有空格吗?
  • 这就是我所希望的,让它变得更简单。

标签: linux bash awk paste


【解决方案1】:

使用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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    相关资源
    最近更新 更多