合并多个CSV文件AWK列明智的,不匹配 [英] Merge multiple csv files awk column-wise, no match
本文介绍了合并多个CSV文件AWK列明智的,不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我敢肯定,这是一个没有脑子,可能已经问,但我一直在寻找永远了。很抱歉的愚蠢的问题!
我要合并的多个 CSV文件:
文件1
A,B
A,B
A,B
文件2
Ç
C
C
FILE3
D
ð
ð
和我想得
A,B,C,D
A B C D
A B C D
我其实是询问抱歉。
非常感谢你让我的生活更轻松,虽然。
解决方案
与胶(由空格分隔)
粘贴-d'文件1文件2
使用awk
的awk'{S = $ 0;函数getline< 文件2打印S,$ 0}'文件1
编辑要求的变化:
肯特$ AWK'{A [FNR] = A [FNR] A [FNR],$ 0:$ 0〜} END {为(i = 1; I< = FNR ;我++)打印[I]}'F1 F2 F3
A B C D
A B C D
A B C D
在这里,您可以后添加更多文件 F1 F2 F3 ...
我没有使用函数getline
在这里,因为我不知道有多少文件,你有,如果足够多,我们可能有打开的文件太多问题。
I'm sure this is a no-brainer and probably has been asked but I've been searching for ever now. So sorry for the dumb question!
I want to merge multiple CSV files:
File1
A, B
A, B
A, B
File2
C
C
C
File3
D
D
D
and I want to yield
A, B, C, D
A, B, C, D
A, B, C, D
I'm actually sorry for asking. Thanks so much you making my life easier, though.
解决方案
with paste (separated by space)
paste -d' ' file1 file2
with awk
awk '{s=$0;getline < "file2";print s,$0}' file1
EDIT for the requirement change:
kent$ awk '{a[FNR]=a[FNR]?a[FNR]", "$0:$0}END{for(i=1;i<=FNR;i++)print a[i]}' f1 f2 f3
A, B, C, D
A, B, C, D
A, B, C, D
Here you can add more files after f1 f2 f3...
I didn't use getline
here because I don't know how many files do you have, if it more enough, we may have "too many open files" problem.
这篇关于合并多个CSV文件AWK列明智的,不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文