linux - 在 Unix 中合并来自多个文件的列

标签 linux shell unix

我需要帮助合并两个竖线分隔文件的内容。

我有

文件1

a|b|1|test|0
v|3|r|rest|4
5|4|a|two|3
3|5|r|help|4

文件2

01May2014

我要

文件3

a|b|1|test|0|01May2014
v|3|r|rest|4|01May2014
5|4|a|two|3|01May2014
3|5|r|help|4|01May2014

任何帮助,尤其是涉及“awk”语句的帮助,我们将不胜感激。

最佳答案

使用 AWK 语言,这是一种方法:

awk 'FNR==NR { r = $0; next } { print $0, r }' OFS="|" file2 file1

结果:

a|b|1|test|0|01May2014
v|3|r|rest|4|01May2014
5|4|a|two|3|01May2014
3|5|r|help|4|01May2014

关于linux - 在 Unix 中合并来自多个文件的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23692637/

相关文章:

c - 高效切换堆栈

python - 在 bash 中使用 NULL 字节(缓冲区溢出)

mongodb - 在 Ubuntu 中使用 shell 脚本更新 YAML 文件

linux - 如何在unix中逐行分割给定的字符串

linux - 在 tcsh 中定义 shell 环境变量

linux - 创建按状态排序的流程列表

python - pysvn 1.6.3 可以在 linux 下与 Subversion 1.6 一起工作吗?

regex - shell脚本中的动态字符串搜索

python - 在 Python 输出中引用 POSIX shell 特殊字符

linux - Centos 5.4 找不到 semanage 命令