Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 如何将日志文件的行转换为列?_Unix_Awk - Fatal编程技术网

Unix 如何将日志文件的行转换为列?

Unix 如何将日志文件的行转换为列?,unix,awk,Unix,Awk,考虑如下所示的日志文件 Operation=someOperation RequestId=giufiudf-fdsfdsg0-314243-df45 RemoteIpAddress=192.168.1.1 Time=151010.473 ms EndTime=Tue, 24 Jul 2012 22:23:46 UTC StartTime=1343168475.480 EOE ------------------------------------------------------------

考虑如下所示的日志文件

Operation=someOperation
RequestId=giufiudf-fdsfdsg0-314243-df45
RemoteIpAddress=192.168.1.1
Time=151010.473 ms
EndTime=Tue, 24 Jul 2012 22:23:46 UTC
StartTime=1343168475.480
EOE
------------------------------------------------------------------------

Operation=someOtherOperation
RequestId=giufiu2323df-fdssadasfdsg0-31424sdesa3-df45
RemoteIpAddress=192.168.1.1
Time=1210.473 ms
EndTime=Tue, 24 Jul 2012 22:23:46 UTC
StartTime=1342128475.480
EOE
------------------------------------------------------------------------

我想要这种格式的输出

Operation          RequestId     RemoteIpAddress    Time          EndTime    StartTime
someOperation         <req id>      192.168.1.1     151010.473 ms  <end Time>  <start time>
someOtherOperation    <req id>      192.168.1.1     1210.473 ms    <end Time>  <start time>
操作请求ID远程IP地址时间结束时间开始时间
某些操作192.168.1.1 151010.473毫秒
其他操作192.168.1.1 1210.473毫秒
提前谢谢




单向使用
awk

awk -F= 'BEGIN { RS=""; OFS="\t" } { for (i = 1; i < NF - 1; i++) { if (i%2==1 && NR == 1) header = (header ? header OFS : "") $i; else if (i%2==0) line = (line ? line OFS : "") $i; } if (header != "") { print header; } print line; header = line = "" }' file.txt

单向使用
awk

awk -F= 'BEGIN { RS=""; OFS="\t" } { for (i = 1; i < NF - 1; i++) { if (i%2==1 && NR == 1) header = (header ? header OFS : "") $i; else if (i%2==0) line = (line ? line OFS : "") $i; } if (header != "") { print header; } print line; header = line = "" }' file.txt
BEGIN {
    RS = ""
    FS= "="
    OFS = "\t"
}

{
    for (i = 1; i < NF - 1; i++) {
        if (i%2==1 && NR == 1) {
            header = (header ? header OFS : "") $i
        }
        else if (i%2==0) {
            line = (line ? line OFS : "") $i
        }
    }

    if (header != "") { print header }
    print line; header = line = ""
}
Operation   RequestId   RemoteIpAddress Time    EndTime StartTime
someOperation   giufiudf-fdsfdsg0-314243-df45   192.168.1.1 151010.473 ms   Tue, 24 Jul 2012 22:23:46 UTC   1343168475.480
someOtherOperation  giufiu2323df-fdssadasfdsg0-31424sdesa3-df45 192.168.1.1 1210.473 ms Tue, 24 Jul 2012 22:23:46 UTC   1342128475.480