连接 12 列的最简单方法是什么?
我有 12 列,由制表符分隔。 我怎样才能并肩加入他们?
[已添加] 你也可以告诉我其他方法,如AWK:越快越好。
I have 12 columns separated by a tab. How can I join them side-by-side?
[Added] You can also tell me other methods as AWK: the faster the better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
由于您具体询问了 awk (有更适合该工作的工具),因此以下是第一个解决方案:
一个更复杂且可配置的解决方案,您可以在其中更改用于输出的列数,将是:
其他可能性,如果您不限于 awk,则:
根据您的编辑和评论,我建议 cut 是完成这项工作的最佳工具。 使用“
man cut
”、“info cut
”或“cut --help
”了解更多详细信息(这取决于您的平台)。Since you asked specifically about awk (there are tools better suited to the job), the following is a first-cut solution:
A more complicated and configurable solution, where you could change the number of columns used for output, would be:
Other possibilities, if you're not restricted to awk, are:
Based on your edit and comments, I suggest cut is the best tool for the job. Use "
man cut
", "info cut
" or "cut --help
" for more details (this depends on your platform).如果您只是使用 awk 来连接列,我将使用 'tr' 并删除选项卡
If you are just using awk to concatenate the columns I would use 'tr' and delete tab
试试这个:
我不是 awk 天才,所以我不知道是否有某种可以使用的循环结构。
Try this:
I'm not an
awk
genius so I don't know if there's some sort of looping construct you can use.嗯,这取决于您选择的编辑器/命令。 但总的来说,归根结底就是用什么东西代替这个角色。
例如,在 vim 中:“
:%s/\t//g
”Well, it depends on your editor/command of choice. But generally, it boild down to replacing the character with nothing.
For example, in vim: "
:%s/\t//g
"您没有提到您想使用什么工具,但任何文本编辑器都可以将制表符替换为空字符,我想这会起作用,这就是我通常所做的。
You did not mention what tool you would like to use but any text editor would be able to replace the tab to an empty character, I guess that would work, that's what I usually do.