无法从文件的不同行打印不同的值 [英] can't manage to print different values from different rows from file
本文介绍了无法从文件的不同行打印不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从一行中的两行打印值.我在数组中使用awk,但是不能这样做.我有一个文件:
i am trying to print values from two rows in one row. I am using awk with arrays, but can't do that. I have a file:
1 00 ERROR
124 00 INFO
1 01 ERROR
60 01 INFO
1 02 ERROR
44 02 INFO
...
,并希望得到类似的东西:
and would like to get something like that:
00 1 124
01 1 60
02 1 44
...
推荐答案
-
纯 POSIX 外壳(即
bash
,dash
等):
while read a b c && read d e f ; do echo $b $a $d ; done < afile
GNU datamash
:
GNU datamash
:
datamash -W -g2 unique 1 < afile | tr ',\t' ' '
其中任何一个输出:
00 1 124
01 1 60
02 1 44
这篇关于无法从文件的不同行打印不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文