- 论坛徽章:
- 23
|
回复 41# rm-rf
我这边测试了下,还是 sed 快一点,暂时没找到原因。- $ time awk '/^mbegin/{print a[NR%3];exit}{a[NR%3]=$2}' file
- 56
- real 1m54.629s
- user 1m53.842s
- sys 0m0.802s
- $ time awk '/^mbegin/{print a[NR%3];exit}{a[NR%3]=$2}' file
- 56
- real 1m53.477s
- user 1m52.826s
- sys 0m0.718s
- $ time sed -r '1{N;N};N;/\nmbegin/{s/^[^ ]* ([^ \n]+).*/\1/;q};$d;D' file
- 56
- real 1m37.946s
- user 1m37.047s
- sys 0m0.888s
- $ time sed -r '1{N;N};N;/\nmbegin/{s/^[^ ]* ([^ \n]+).*/\1/;q};$d;D' file
- 56
- real 1m36.611s
- user 1m35.938s
- sys 0m0.716s
- $ du -sh file
- 2.3G file
- $ sed --version
- GNU sed version 4.2.1
- Copyright (C) 2009 Free Software Foundation, Inc.
- $ awk --version
- GNU Awk 3.1.7
- Copyright (C) 1989, 1991-2009 Free Software Foundation.
复制代码 |
|