同一文件中两列的串联 [英] Concatenation of two columns from the same file

查看:56
本文介绍了同一文件中两列的串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自文本文件

文件

a    d
b    e
c    f

以制表符分隔的列如何串联成一列

how are the tab delimited columns concatenated into one column

a
b
c
d
e
f

现在,我使用 awk 将列输出到两个文件,然后使用 cat 进行连接.但是必须有更好的一行命令吗?

Now I use awk to output columns to two files that I then concatenated using cat. But there must be a better one line command?

推荐答案

用于通用方法

$ f() { awk '{print $'$1'}' file; }; f 1; f 2

a
b
c
d
e
f

如果文件是用制表符分隔的,则可以简单地用cut(paste的反操作)

if the file is tab delimited perhaps simply with cut (the inverse operation of paste)

$ cut -f1 file.t; cut -f2 file.t

这篇关于同一文件中两列的串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆