この広告は、90日以上更新していないブログに表示しています。
追記が増えたので整理
2.5GBのテキストファイルを加工する必要があり、①vimで開いて加工→vim死亡②sublime textで開いて加工→sublime text死亡となったため、awkを用いて以下の様なコマンドを実行した。
$ cat sample.txt | awk'$5 ~ /((26|27|28|29|30)\/Jun|(01|02|03)\/Jul)/{ print }'> result.txt
すると
とコメントをもらいました。ので、どっちが速いかの検証です。
※ 以下のような方法で計測していたところ、、、、
$time awk'$5 ~ /((26|27|28|29|30)\/Jun|(01|02|03)\/Jul)/{ print }' sample.txt> result1.txt
Twitterにてご指摘をいただきました。
@matsumotory あ、time コマンドが cat にしか効いてない...
— Shigeki Morimoto (@shmorimo)July 22, 2015すると、、
@tap1ra time sh -c "command" みたいにすればtimeで測れますね
— ぶてい (@buty4649)July 22, 2015と回避策を教えていただいたので、再度計測しました。
# $ time shに渡すときシングルクォーテーションのエスケープ方法がわからず、ファイルにした# $ time command1.shでも良かったのかも。[root@localhost sample]# cat command1awk'$5 ~ /((26|27|28|29|30)\/Jun|(01|02|03)\/Jul)/{ print }' sample.txt> result1.txt# キャッシュ削除処理[root@localhost sample]#echo 1> /proc/sys/vm/drop_caches;echo 2> /proc/sys/vm/drop_caches;echo 3> /proc/sys/vm/drop_caches[root@localhost sample]# free total used free shared buffers cachedMem:502160531884489724685007716-/+ buffers/cache:44972457188Swap:101580401015804[root@localhost sample]#time sh command1real 0m53.926suser 0m0.926ssys 0m33.158s
[root@localhost sample]# cat command2cat sample.txt | awk'$5 ~ /((26|27|28|29|30)\/Jun|(01|02|03)\/Jul)/{ print }'> result2.txt[root@localhost sample]#echo 1> /proc/sys/vm/drop_caches;echo 2> /proc/sys/vm/drop_caches;echo 3> /proc/sys/vm/drop_caches[root@localhost sample]# free total used free shared buffers cachedMem:502160529644491964682367716-/+ buffers/cache:45012457148Swap:101580401015804[root@localhost sample]#time sh command2real 0m30.789suser 0m2.644ssys 0m22.277s
# できあがったブツに差異はなさそう[root@localhost sample]# md5sum result1.txtff6a7bf31b5ba8bdbba619258c0c4285 result1.txt[root@localhost sample]# md5sum result2.txtff6a7bf31b5ba8bdbba619258c0c4285 result2.txt
条件によるとは思うけど、catしたほうがはやいっぽい。
中身的な分析でとても参考になるエントリ:大きなテキストファイルをawkで処理するときにcatで投げ込むと速い理由 - ablog
引用をストックしました
引用するにはまずログインしてください
引用をストックできませんでした。再度お試しください
限定公開記事のため引用できません。