将文本文件中的行与命令行对齐

Align rows in text file with command line

我在一个文本文件中有数据,其中数据行在几列之后重复,并且每个新块共享行标签的第一列。我想使用命令行将行对齐到单个 table.

数据文本文件如下所示:

Values      SampleA     SampleB     SampleC
Value1      1.00        2.00        3.00
Value2      3.00        2.00        1.00
Value3      2.00        1.00        3.00

Values      SampleD     SampleE     SampleF
Value1      1.00        2.00        3.00
Value2      3.00        2.00        1.00
Value3      2.00        1.00        3.00

我希望生成的文件看起来像:

Values      SampleA     SampleB     SampleC     SampleD     SampleE     SampleF
Value1      1.00        2.00        3.00        1.00        2.00        3.00
Value2      3.00        2.00        1.00        3.00        2.00        1.00
Value3      2.00        1.00        3.00        2.00        1.00        3.00

此解决方案会创建大量临时文件,但会在之后进行清理。

# put each paragraph into it's own file:
awk -v RS= '{print > sprintf("%s_%06d", FILENAME, NR)}' data.txt 

# now, join them, and align the columns 
join data.txt_* | column -t | tee data.txt.joined

# and cleanup the temp files
rm data.txt_*

之后验证:wc -l data.txt data.txt.joined