0

以下のようなログファイルを検討してください

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>

前もって感謝します.. !!

4

2 に答える 2

2

http://www.gnu.org/software/gawk/manual/html_node/Field-Separators.html
http://www.gnu.org/software/gawk/manual/html_node/Concatenation.html

BEGIN {
    FS="="
}

$0~/^EOE/ {
    if (!f) {
    print header
    f = 1
    }
    print data
    data = ""
}

NF==2 {
   data = data " " $2
}

!f {
    header = header " " $1
}
于 2012-07-25T09:16:45.457 に答える
1

を使用した片道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
于 2012-07-25T13:29:39.167 に答える