21/11/03 09:59:44.46 .net
テキトーに色々
$ for i in {1..2000000}; do echo aaaa; echo bbbb; echo cccc; echo $i; echo dddd; echo eeee; echo ffff; echo gggg; echo; done > aaa
$ time (awk 'function keepp () { if (matched) { for (i=0 ; i < nkeeps ; i++) print keeps[i]; print } matched=0; nkeeps=0 } NF == 0 { keepp(); next } { keeps[nkeeps++]=$0; if ($1 == "1414213") matched=1 } END{ keepp() }' < aaa )
real 0m10.556s
user 0m10.281s
sys 0m0.271s
$ time (awk 'NF == 0 { print; next } { printf "%s ", $0 }' < aaa | grep '\<1414213\>' | tr ' ' '\n')
real 0m11.101s
user 0m1.177s
sys 0m12.259s
$ time (tr '\n' ' ' < aaa | sed -e 's/ /\
/g' | grep '\<1414213\>' | tr ' ' '\n')
real 0m2.344s
user 0m1.452s
sys 0m0.814s
$ time (tr '\n' ' ' < aaa | sed -e 's/ */\
/g' | grep '\<1414213\>' | tr ' ' '\n')
real 0m3.678s
user 0m1.484s
sys 0m1.078s