linux 中 根据制定列标签展开为两列以及依据两列信息进行合并

发布时间 2023-07-22 10:11:35作者: 小鲨鱼2018

 

001、

[root@PC1 test05]# ls
result.txt
[root@PC1 test05]# cat result.txt                   ## 测试数据
2       23669   23709
2       23517   23696
3       23515   23708
3       23556   23713
4       23476   23711
4       23622   23720                                       ## 依据第一列展开
[root@PC1 test05]# awk '{OFS = "\t"; print $1, $2; print $1, $3}' result.txt | tee result2.txt
2       23669
2       23709
2       23517
2       23696
3       23515
3       23708
3       23556
3       23713
4       23476
4       23711
4       23622
4       23720

 

002、

[root@PC1 test05]# ls
result2.txt  result.txt
[root@PC1 test05]# cat result2.txt         ## 测试数据
2       23669
2       23709
2       23517
2       23696
3       23515
3       23708
3       23556
3       23713
4       23476
4       23711
4       23622
4       23720                             ## 根据第一列数据合并
[root@PC1 test05]# awk '{printf("%s\t", $0); getline; print $2}' result2.txt
2       23669   23709
2       23517   23696
3       23515   23708
3       23556   23713
4       23476   23711
4       23622   23720