简体   繁体   English

如何使用sed或awk将单个列中的元素排列为多个?

[英]How to arrange elements that is there in a single column to multiple using sed or awk?

My File content: 我的文件内容:

Apple
Banana
orange
Donkey
Elephant
Fox
Good

I am trying to arrange elements that is there in a single column(as shown above) into two columns as shown below: 我正在尝试将单列(如上所示)中的元素排列成两列,如下所示:

Expected output: 预期产量:

Apple          Banana
Orange         Donkey
Elephant       Fox
Good

Is there any way in Sed or awk to achieve this? Sed或awk中有什么方法可以实现这一目标吗?

How about something like 怎么样

$ awk 'ORS=(NR%2)?" ":"\n"' input
Apple Banana
orange Donkey
Elephant Fox
Good 

OR 要么

$ awk 'ORS=(NR%2)?FS:RS' input | column -t
Apple     Banana
orange    Donkey
Elephant  Fox
Good

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM