必要な部分文字列/文字列を取得するより高速なawkスクリプト

必要な部分文字列/文字列を取得するより高速なawkスクリプト
ORDER EVENT .........[] [] ... so many other tags... [Account<25106>=ACCT1] [Destination...] .. so many other tags.

私は現在そのようなアカウントを取得しようとしています。 awkでmatchを使ってみましたが、遅いようです。以下のより速い方法に加えて、他のものを提案してもらえますか?

j = index($0, "<25106>=");
account=substr($0, j + accountTagLength);
account=substr(account,1,index(account, "]") - 1);

アカウントは 2 番目のフィールドではなく、フィールドの場所は異なる場合があります。

時間:

bash-3.2$ time head -1000000 temp.log | awk -F'<25106>=' '{print $2}' | sed -e 's/].*//' > /dev/null

real    0m2.410s
user    0m2.782s
sys     0m0.319s
bash-3.2$ time head -1000000 temp.log | awk '{j = index($0, "25106>="); if (j > 0) { account=substr($0, j + 7); substr(account,1,index(account, "]") - 1);} }'

real    0m1.690s
user    0m1.737s
sys     0m0.448s
bash-3.2$ time head -1000000 temp.log | awk '{j = index($0, "25106>="); if (j > 0) { account=substr($0, j + 7); substr(account,1,index(account, "]") - 1);} }'

real    0m1.588s
user    0m1.733s
sys     0m0.179s
bash-3.2$ time head -1000000 temp.log | awk -F'<25106>=' '{print $2}' | sed -e 's/].*//' > /dev/null                               
real    0m2.384s
user    0m2.762s
sys     0m0.272s
bash-3.2$ time head -1000000 temp.log | awk '{j = index($0, "25106>="); if (j > 0) { account=substr($0, j + 7); substr(account,1,index(account, "]") - 1);} }'

real    0m1.703s
user    0m1.709s
sys     0m0.484s

bash-3.2$ time head -1000000 dumper/cam_verbose.20120220.000.log | gawk 'match($0, /<25106>=([^]]+)/, ary) {account = ary[1]}'

real    0m3.449s
user    0m3.661s
sys     0m0.290s
bash-3.2$ time head -1000000 dumper/cam_verbose.20120220.000.log | gawk 'match($0, /<25106>=([^]]+)/, ary) {account = ary[1]}'

real    0m3.410s
user    0m3.551s
sys     0m0.236s
bash-3.2$ time head -1000000 dumper/cam_verbose.20120220.000.log | gawk 'match($0, /<25106>=([^]]+)/, ary) {account = ary[1]}'

real    0m3.361s
user    0m3.487s
sys     0m0.286s
bash-3.2$ time head -1000000 dumper/cam_verbose.20120220.000.log | awk '{j = index($0, "25106>="); if (j > 0) { account=substr($0, j + 7); substr(account,1,index(account, "]") - 1);} }'

real    0m1.626s
user    0m1.831s
sys     0m0.263s
bash-3.2$ time head -1000000 dumper/cam_verbose.20120220.000.log | awk -F '<25106>=' '{split($2, ary, /\]/); account = ary[1]}'

real    0m2.721s
user    0m2.808s
sys     0m0.265s
bash-3.2$ time head -1000000 dumper/cam_verbose.20120220.000.log | awk -F '<25106>=' '{split($2, ary, /\]/); account = ary[1]}'

real    0m2.787s
user    0m2.863s
sys     0m0.516s
bash-3.2$ time head -1000000 dumper/cam_verbose.20120220.000.log | awk -F '<25106>=' '{split($2, ary, /\]/); account = ary[1]}'

real    0m2.724s
user    0m2.882s
sys     0m0.278s
bash-3.2$ time head -1000000 dumper/cam_verbose.20120220.000.log | awk '{j = index($0, "25106>="); if (j > 0) { account=substr($0, j + 7); substr(account,1,index(account, "]") - 1);} }'

real    0m1.576s
user    0m1.748s
sys     0m0.235s

bash-3.2$ time head -100000 ORDER_EVENTS_CHAS_20120224.log | grep -oE '<25106>=([A-Za-z0-9]*)+' | cut -d= -f2 > /dev/null                                     
real    0m2.098s
user    0m2.131s
sys     0m0.033s
bash-3.2$ time head -100000 ORDER_EVENTS_CHAS_20120224.log | awk '{j = index($0, "25106>="); if (j > 0) { account=substr($0, j + 7); print substr(account,1,index(account, "]") - 1);} }' > /dev/null

real    0m0.253s
user    0m0.275s
sys     0m0.040s
bash-3.2$ time head -100000 ORDER_EVENTS_CHAS_20120224.log | grep -oE '<25106>=([A-Za-z0-9]*)+' | cut -d= -f2 > /dev/null                                     
real    0m2.070s
user    0m2.105s
sys     0m0.034s
bash-3.2$ time head -100000 ORDER_EVENTS_CHAS_20120224.log | grep -oE '<25106>=([A-Za-z0-9]*)+' > /dev/null

real    0m2.065s
user    0m2.090s
sys     0m0.037s
    bash-3.2$ time head -1000000 ORDER_EVENTS_CHAS_20120228.log | awk -F'<25106>=' '{ substr($2,0,index($2,"]")-1);}'

real    0m3.426s
user    0m3.637s
sys     0m0.412s
bash-3.2$ time head -1000000 ORDER_EVENTS_CHAS_20120228.log | awk -F'<25106>=' '{ substr($2,0,index($2,"]")-1);}'

real    0m3.463s
user    0m3.603s
sys     0m0.408s
bash-3.2$ time head -1000000 ORDER_EVENTS_CHAS_20120228.log | awk '{j = index($0, "25106>="); if (j > 0) { account=substr($0, j + 7); substr(account,1,index(account, "]") - 1);} }'

real    0m2.247s
user    0m2.307s
sys     0m0.649s

ベストアンサー1

この試み:

awk -F'<25106>=' '{print substr($2,0,index($2,"]")-1);}'

正規表現を使用せず、厳密な文字列操作のみを使用します。

おすすめ記事