如何在unix中将行转换为列 [英] How to convert rows to columns in unix
本文介绍了如何在unix中将行转换为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望将我的 Unix 文件输出(每个值都在一个新行上输出)转换为如下所示的分组行.
I want my Unix file output, which has each value output on a new line, to be converted into grouped rows as shown below.
假设我在 Unix 中的输出文件如下所示:
Say my output file in Unix looks like this:
jobname
userid
starttime
endtime
jobname2
userid
starttime
endtime
我希望输出为:
jobname1 userid starttime endtime
jobname2 userid starttime endtime
推荐答案
这是一个最小的 awk
解决方案:
This is a minimal awk
solution:
awk 'ORS=NR%4?" ":"\n"' input.txt
输出
jobname userid starttime endtime
jobname2 userid starttime endtime
(如果你想对齐字段,管道到column -t
)
(If you want to align the fields, pipe to column -t
)
这篇关于如何在unix中将行转换为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文