awk的/ sed的/壳合并/连接的数据 [英] awk/sed/shell to merge/concatenate data
本文介绍了awk的/ sed的/壳合并/连接的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图合并一些数据,我有。输入看起来像这样:
Trying to merge some data that I have. The input would look like so:
foo bar
foo baz boo
abc def
abc ghi
和我想的输出如下:
foo bar baz boo
abc def ghi
我使用一些阵列在shell脚本的一些想法,但我一直在寻找一个更优雅的或更快的解决方案。
I have some ideas using some arrays in a shell script, but I was looking for a more elegant or quicker solution.
推荐答案
如何加入?
file="file"
join -a1 -a2 <(sort "$file" | sed -n 1~2p) <(sort "$file" | sed -n 2~2p)
该SEDS还有刚刚分裂奇数和偶数行的文件
The seds there are just splitting the file on odd and even lines
这篇关于awk的/ sed的/壳合并/连接的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文