68user's page 掲示板

Prev< No. 4580> Next  [最新発言に戻る] [過去ログ一覧]
No. 4580 # zsh 2006/04/19 (水) 13:27:30
>>4579 べた
これが賢いやり方とも思えませんが、一応作ってみました。
------
$ cat a.awk
BEGIN {
        FS=",";
        chk_col=11;
} {
        if ($chk_col ~ /:/) {
                str_head=head_string();
                split_num=split($chk_col, str_foot, ":");
                for (i=1; i<=split_num; i++) {
                        for (j=chk_col+1; j<=NF; j++) {
                                split($j, col_buf, ":");
                                str_foot[i]=sprintf("%s,%s", str_foot[i], col_buf[i]);
                        }
                        print str_head "," str_foot[i];
                }
        } else {
                print;
        }
} function head_string() {
        str_buf=$1;
        for (k=2; k<chk_col; k++) {
                str_buf=sprintf("%s,%s", str_buf, $k);
        }
        return str_buf;
}
------
------
$ cat a
001,a2,a3,a4,a5,a6,a7,a8,a9,a10,,,,,,
002,a2,a3,a4,a5,a6,a7,a8,a9,a10,111:222,123:456,001:002,100:200,A01:A02,0:1
003,a2,a3,a4,a5,a6,a7,a8,a9,a10,111:222,123:,:,:,A01:A02,:
------
------
$ awk -f a.awk a
001,a2,a3,a4,a5,a6,a7,a8,a9,a10,,,,,,
002,a2,a3,a4,a5,a6,a7,a8,a9,a10,111,123,001,100,A01,0
002,a2,a3,a4,a5,a6,a7,a8,a9,a10,222,456,002,200,A02,1
003,a2,a3,a4,a5,a6,a7,a8,a9,a10,111,123,,,A01,
003,a2,a3,a4,a5,a6,a7,a8,a9,a10,222,,,,A02,
------

>>4571 68user
今更ですが、Solarisでは

$ echo "Apr 02 12:25:00 ===" | sort -M - logfile | \
    sort -n -k2,3 | cat -n | grep "===" | awk '{print $1}'

等としないとダメみたいです。

Prev< No. 4580> Next  [最新発言に戻る] [過去ログ一覧]