如何在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)